Compare commits

...

27 Commits

Author SHA1 Message Date
Jason Jean 08165463eb chore(misc): publish 15.2.2 2022-11-29 17:37:50 -05:00
Miroslav Jonaš 78861e6ae2 fix(core): generated package.json should not include duplicates and optional peer deeps (#13438)
(cherry picked from commit a95b91d433)
2022-11-28 14:59:35 -05:00
Jason Jean 796fd27f18 fix(misc): add configuration option to print-affected (#13422)
(cherry picked from commit 3653e5944d)
2022-11-28 14:58:52 -05:00
Jason Jean 2eb1897066 fix(core): fix showing help for executors (#13393)
(cherry picked from commit 2c13661b90)
2022-11-28 14:58:23 -05:00
Richard Roozenboom dd5b967be6 fix(devkit): change name schema order in project.json (#13409)
(cherry picked from commit f0fc7863f9)
2022-11-28 14:58:17 -05:00
Katerina Skroumpelou a31aa3ba74 fix(storybook): remove polyfill.ts from tsconfig (#13322)
(cherry picked from commit 13602c3d3b)
2022-11-28 14:57:02 -05:00
Jack Hsu 9b71c53e43 fix(nextjs): check validity of Nx context in withNx plugin (#13358)
(cherry picked from commit dc16468607)
2022-11-28 14:56:47 -05:00
Dominik Pieper 724d3cc074 fix(angular): fix Karma test runner config (#13293)
Co-authored-by: Colum Ferry <cferry09@gmail.com>
(cherry picked from commit e3d8b2c22c)
2022-11-28 14:56:29 -05:00
Elyahou Ittah 8729916da6 fix(nx-plugin): ensure project has eslint available before adding lint checks for migrations.json(#13327)
Fixes https://github.com/nrwl/nx/issues/13326

(cherry picked from commit 90f2791303)
2022-11-28 14:55:25 -05:00
Jack Hsu 8816c51c41 fix(bundling): fix exclude entries for .lib.swcrc file to exclude spe… (#13319)
(cherry picked from commit 1b3abbd477)
2022-11-28 14:55:00 -05:00
Victor Savkin c127d65aa4 fix(misc): axios import breaks when using npx
(cherry picked from commit 19018fcdd1)
2022-11-28 14:54:02 -05:00
Leosvel Pérez Espinosa 31326f239d fix(angular): update make-angular-cli-faster version map with angular 15 (#13297)
(cherry picked from commit da2b77aeb7)
2022-11-28 14:53:53 -05:00
ccosmincc 3ac2e8e662 fix(angular): checks for targets existence before attempting to iterate them (#13287)
(cherry picked from commit 328c54787f)
2022-11-28 14:53:33 -05:00
Paulo Fernandes fb2e47ccf3 fix(linter): align reportUnusedDisableDirectives default value (#13284)
Co-authored-by: pfernandes <paulo.fernandes@dashlane.com>
(cherry picked from commit 2772fab0e7)
2022-11-28 14:53:22 -05:00
Leosvel Pérez Espinosa 8d56b1b425 fix(angular): use the browserTarget to calculate project deps for buildable libs support in the dev server (#13275)
(cherry picked from commit 18306696dc)
2022-11-28 14:52:48 -05:00
Jason Jean 87b2b5c085 chore(misc): publish 15.2.1 2022-11-18 19:44:48 -05:00
Jason Jean 89f8a53578 fix(core): use multiselect prompts for array properties (#13270)
(cherry picked from commit 3af70fc647)
2022-11-18 19:42:03 -05:00
Jason Jean b402abe239 chore(repo): fix issues building nx-dev
(cherry picked from commit 55c20b81c0)
2022-11-18 19:06:41 -05:00
Jason Jean e85804fa41 chore(repo): fix includedScripts typo
(cherry picked from commit 33154c344f)
2022-11-18 19:06:39 -05:00
Victor Savkin 7f8af1a8ae chore(repo): use root-level scripts
(cherry picked from commit ffd40af446)
2022-11-18 18:25:34 -05:00
Katerina Skroumpelou b1c05fee48 fix(bundling): file replacement for vite (#13255)
(cherry picked from commit e4092aa47f)
2022-11-18 18:20:56 -05:00
Katerina Skroumpelou 22d9031b96 fix(bundling): remove the vue options from vite gen (#13221)
(cherry picked from commit ab93817d44)
2022-11-18 18:20:50 -05:00
Colum Ferry aa2ee2d326 fix(angular): should support filereplacements for apps that already have them (#13247)
(cherry picked from commit b4fb074a09)
2022-11-18 18:20:47 -05:00
Miroslav Jonaš 951a364a13 cleanup(core): move lock-file utils to root nx level (#13245)
(cherry picked from commit b2b161cb8d)
2022-11-18 18:20:43 -05:00
Colum Ferry 1b9c7df62c fix(angular): setup-ssr environments file replacements should be removed (#13244)
(cherry picked from commit b88dc35aa5)
2022-11-18 18:20:34 -05:00
Colum Ferry 4c2e5aaf00 fix(angular): setup-ssr should output correct outpathPath for server build (#13243)
(cherry picked from commit e041223020)
2022-11-18 18:20:32 -05:00
Michał Mrozek c0ee01f924 fix(angular): local imports in webpack-dev-server custom config (#13156)
(cherry picked from commit e971ffba71)
2022-11-18 18:20:28 -05:00
66 changed files with 435 additions and 365 deletions
+7 -7
View File
@@ -176,7 +176,7 @@ jobs:
- run: npx nx-cloud start-ci-run --stop-agents-after="e2e"
- run:
name: Check Documentation
command: npx nx-cloud record yarn documentation
command: npx nx documentation --no-dte
no_output_timeout: 20m
- run:
name: Run Checks/Lint/Test/Build
@@ -184,12 +184,12 @@ jobs:
command: |
pids=()
(npx nx-cloud record yarn check-imports &&
npx nx-cloud record yarn nx format:check --base=$NX_BASE --head=$NX_HEAD &&
npx nx-cloud record yarn check-commit &&
npx nx-cloud record yarn check-lock-files &&
npx nx-cloud record yarn nx workspace-lint &&
npx nx-cloud record yarn depcheck) &
(npx nx check-imports --no-dte &&
npx nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD &&
npx nx check-commit --no-dte &&
npx nx check-lock-files --no-dte &&
npx nx lint --no-dte &&
npx nx depcheck --no-dte ) &
pids+=($!)
yarn nx affected --target=lint --base=$NX_BASE --head=$NX_HEAD --parallel=3 &
+1
View File
@@ -14,6 +14,7 @@ packages/react/src/schematics/**/files/**/*.json
packages/jest/src/schematics/**/files/**/*.json
packages/**/schematics/**/files/**/*.html
packages/**/generators/**/files/**/*.html
nx-dev/nx-dev/.next/
/.vscode
/.idea
/.github
+1 -1
View File
@@ -250,7 +250,7 @@ Please follow the following guidelines:
- Debug with `node --inspect-brk ./node_modules/jest/bin/jest.js build/packages/angular/src/utils/ast-utils.spec.js`
- Make sure e2e tests pass (this can take a while, so you can always let CI check those) (`nx affected --target=e2e`)
- Target a specific e2e test with `nx e2e e2e-cypress`
- Make sure you run `yarn format`
- Make sure you run `nx format`
- Update documentation with `yarn documentation`. For documentation, check for spelling and grammatical errors.
- Update your commit message to follow the guidelines below (use `yarn commit` to automate compliance)
- `yarn check-commit` will check to make sure your commit messages are formatted correctly
+6
View File
@@ -61,6 +61,12 @@ Type: `string`
Base of the current branch (usually main)
### configuration
Type: `string`
This is the configuration to use when performing tasks on projects
### exclude
Type: `array`
-1
View File
@@ -206,7 +206,6 @@
},
"reportUnusedDisableDirectives": {
"type": "string",
"default": "off",
"enum": ["off", "warn", "error"],
"description": "The equivalent of the `--report-unused-disable-directives` flag on the ESLint CLI."
}
+1 -1
View File
@@ -81,7 +81,7 @@
"name": "print-affected",
"id": "print-affected",
"file": "generated/cli/print-affected",
"content": "---\ntitle: 'print-affected - CLI command'\ndescription: 'Prints information about the projects and targets affected by changes'\n---\n\n# print-affected\n\nPrints information about the projects and targets affected by changes\n\n## Usage\n\n```terminal\nnx print-affected\n```\n\nInstall `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`.\n\n### Examples\n\nPrint information about affected projects and the project graph:\n\n```terminal\n nx print-affected\n```\n\nPrint information about the projects affected by the changes between main and HEAD (e.g,. PR):\n\n```terminal\n nx print-affected --base=main --head=HEAD\n```\n\nPrints information about the affected projects and a list of tasks to test them:\n\n```terminal\n nx print-affected --target=test\n```\n\nPrints the projects property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=projects\n```\n\nPrints the tasks.target.project property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=tasks.target.project\n```\n\n## Options\n\n### all\n\nType: `boolean`\n\nAll projects\n\n### base\n\nType: `string`\n\nBase of the current branch (usually main)\n\n### exclude\n\nType: `array`\n\nDefault: `[]`\n\nExclude certain projects from being processed\n\n### files\n\nType: `array`\n\nChange the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas\n\n### head\n\nType: `string`\n\nLatest commit of the current branch (usually HEAD)\n\n### help\n\nType: `boolean`\n\nShow help\n\n### select\n\nType: `string`\n\nSelect the subset of the returned json document (e.g., --select=projects)\n\n### target\n\nType: `string`\n\nTask to run for affected projects\n\n### type\n\nType: `string`\n\nChoices: [app, lib]\n\nSelect the type of projects to be returned (e.g., --type=app)\n\n### uncommitted\n\nType: `boolean`\n\nUncommitted changes\n\n### untracked\n\nType: `boolean`\n\nUntracked changes\n\n### version\n\nType: `boolean`\n\nShow version number\n"
"content": "---\ntitle: 'print-affected - CLI command'\ndescription: 'Prints information about the projects and targets affected by changes'\n---\n\n# print-affected\n\nPrints information about the projects and targets affected by changes\n\n## Usage\n\n```terminal\nnx print-affected\n```\n\nInstall `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`.\n\n### Examples\n\nPrint information about affected projects and the project graph:\n\n```terminal\n nx print-affected\n```\n\nPrint information about the projects affected by the changes between main and HEAD (e.g,. PR):\n\n```terminal\n nx print-affected --base=main --head=HEAD\n```\n\nPrints information about the affected projects and a list of tasks to test them:\n\n```terminal\n nx print-affected --target=test\n```\n\nPrints the projects property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=projects\n```\n\nPrints the tasks.target.project property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=tasks.target.project\n```\n\n## Options\n\n### all\n\nType: `boolean`\n\nAll projects\n\n### base\n\nType: `string`\n\nBase of the current branch (usually main)\n\n### configuration\n\nType: `string`\n\nThis is the configuration to use when performing tasks on projects\n\n### exclude\n\nType: `array`\n\nDefault: `[]`\n\nExclude certain projects from being processed\n\n### files\n\nType: `array`\n\nChange the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas\n\n### head\n\nType: `string`\n\nLatest commit of the current branch (usually HEAD)\n\n### help\n\nType: `boolean`\n\nShow help\n\n### select\n\nType: `string`\n\nSelect the subset of the returned json document (e.g., --select=projects)\n\n### target\n\nType: `string`\n\nTask to run for affected projects\n\n### type\n\nType: `string`\n\nChoices: [app, lib]\n\nSelect the type of projects to be returned (e.g., --type=app)\n\n### uncommitted\n\nType: `boolean`\n\nUncommitted changes\n\n### untracked\n\nType: `boolean`\n\nUntracked changes\n\n### version\n\nType: `boolean`\n\nShow version number\n"
},
{
"name": "format:check",
+1 -1
View File
@@ -28,7 +28,7 @@
"uiFramework": {
"type": "string",
"description": "UI Framework to use for Vite.",
"enum": ["react", "vue3", "vue3-jsx"],
"enum": ["react", "none"],
"default": "react",
"x-prompt": "What UI framework plugin should Vite use?"
}
+3 -4
View File
@@ -227,7 +227,9 @@ describe('Node Applications', () => {
describe('Build Node apps', () => {
beforeEach(() => newProject());
it('should generate a package.json with the `--generatePackageJson` flag', async () => {
afterEach(() => cleanupProject());
it('should generate a package.json with the `--generatePackageJson` flag MMM', async () => {
const scope = newProject();
const nestapp = uniq('nestapp');
runCLI(`generate @nrwl/nest:app ${nestapp} --linter=eslint`);
@@ -251,9 +253,6 @@ describe('Build Node apps', () => {
expect(
satisfies(packageJson.dependencies['@nestjs/core'], '^9.0.0')
).toBeTruthy();
expect(
satisfies(packageJson.dependencies['@nestjs/platform-express'], '^9.0.0')
).toBeTruthy();
expect(
satisfies(packageJson.dependencies['reflect-metadata'], '^0.1.13')
).toBeTruthy();
+1 -1
View File
@@ -1,6 +1,6 @@
{
"packages": ["build/packages/*"],
"version": "15.2.0",
"version": "15.2.2",
"granularPathspec": false,
"command": {
"publish": {
+1 -8
View File
@@ -3,7 +3,6 @@
"affected": {
"defaultBase": "master"
},
"npmScope": "nrwl",
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/nx-cloud",
@@ -86,11 +85,5 @@
"inputs": ["default", "^production", "{workspaceRoot}/.storybook/**/*"]
}
},
"generators": {
"@nrwl/react": {
"application": {
"babel": true
}
}
}
"defaultProject": "@nrwl/nx-source"
}
+14 -3
View File
@@ -10,11 +10,9 @@
"check-format": "nx format:check --all",
"check-imports": "node ./scripts/check-imports.js",
"check-lock-files": "node ./scripts/check-lock-files.js",
"check-versions": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/check-versions.ts",
"check-documentation-map": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/documentation/map-link-checker.ts",
"e2e-start-local-registry": "node ./scripts/e2e-start-local-registry.js",
"e2e-build-package-publish": "ts-node -P ./scripts/tsconfig.e2e.json ./scripts/e2e-build-package-publish.ts",
"format": "nx format",
"nx-release": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/nx-release",
"prepublishOnly": "node ./scripts/update-package-group.js",
"version": "npx prettier lerna.json --write",
@@ -23,7 +21,8 @@
"documentation": "ts-node -P scripts/tsconfig.scripts.json ./scripts/documentation/documentation.ts && yarn check-documentation-map",
"submit-plugin": "node ./scripts/submit-plugin.js",
"prepare": "is-ci || husky install",
"echo": "echo 123458"
"echo": "echo 123458",
"lint": "nx workspace-lint"
},
"devDependencies": {
"@angular-devkit/architect": "~0.1500.0",
@@ -308,6 +307,18 @@
"**/xmlhttprequest-ssl": "~1.6.2",
"minimist": "^1.2.6",
"underscore": "^1.12.1"
},
"nx": {
"includedScripts": [
"echo",
"check-commit",
"check-format",
"check-imports",
"check-lock-files",
"depcheck",
"documentation",
"lint"
]
}
}
@@ -9,14 +9,15 @@ import { join } from 'path';
export function createTmpTsConfigForBuildableLibs(
tsConfigPath: string,
context: BuilderContext
context: BuilderContext,
target?: string
) {
let dependencies: DependentBuildableProjectNode[];
const result = calculateProjectDependencies(
readCachedProjectGraph(),
context.workspaceRoot,
context.target.project,
context.target.target,
target ?? context.target.target,
context.target.configuration
);
dependencies = result.dependencies;
@@ -69,7 +69,11 @@ export function executeWebpackDevServerBuilder(
const buildTargetTsConfigPath =
buildTargetConfiguration?.tsConfig ?? buildTarget.options.tsConfig;
const { tsConfigPath, dependencies: foundDependencies } =
createTmpTsConfigForBuildableLibs(buildTargetTsConfigPath, context);
createTmpTsConfigForBuildableLibs(
buildTargetTsConfigPath,
context,
parsedBrowserTarget.target
);
dependencies = foundDependencies;
// We can't just pass the tsconfig path in memory to the angular builder
@@ -84,6 +88,12 @@ export function executeWebpackDevServerBuilder(
options.tsConfig = tsConfigPath;
return options;
};
// The buildTargetConfiguration also needs to use the generated tsconfig path
// otherwise the build will fail if customWebpack function/file is referencing
// local libs. This synchronize the behavior with webpack-browser and
// webpack-server implementation.
buildTargetConfiguration.tsConfig = tsConfigPath;
}
return executeDevServerBuilder(options as DevServerBuilderOptions, context, {
@@ -69,3 +69,70 @@ module.exports = function(config) {
};
"
`;
exports[`karmaProject should generate files 1`] = `
"{
\\"extends\\": \\"./tsconfig.json\\",
\\"compilerOptions\\": {
\\"outDir\\": \\"../../dist/out-tsc\\",
\\"types\\": [
\\"jasmine\\",
\\"node\\"
]
},
\\"files\\": [
\\"src/test.ts\\"
],
\\"include\\": [
\\"**/*.spec.ts\\",
\\"**/*.test.ts\\",
\\"**/*.d.ts\\"
]
}
"
`;
exports[`karmaProject should generate files and correctly add polyfills if it is using old ng style polyfills 1`] = `
"{
\\"extends\\": \\"./tsconfig.json\\",
\\"compilerOptions\\": {
\\"outDir\\": \\"../../dist/out-tsc\\",
\\"types\\": [
\\"jasmine\\",
\\"node\\"
]
},
\\"files\\": [
\\"src/test.ts\\",
\\"src/polyfills.ts\\"
],
\\"include\\": [
\\"**/*.spec.ts\\",
\\"**/*.test.ts\\",
\\"**/*.d.ts\\"
]
}
"
`;
exports[`karmaProject should generate files and not add polyfills if it is using ng v15 style polyfills 1`] = `
"{
\\"extends\\": \\"./tsconfig.json\\",
\\"compilerOptions\\": {
\\"outDir\\": \\"../../dist/out-tsc\\",
\\"types\\": [
\\"jasmine\\",
\\"node\\"
]
},
\\"files\\": [
\\"src/test.ts\\"
],
\\"include\\": [
\\"**/*.spec.ts\\",
\\"**/*.test.ts\\",
\\"**/*.d.ts\\"
]
}
"
`;
@@ -1,5 +1,9 @@
import type { Tree } from '@nrwl/devkit';
import * as devkit from '@nrwl/devkit';
import {
readProjectConfiguration,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing';
import { karmaProjectGenerator } from './karma-project';
import libraryGenerator from '../library/library';
@@ -46,10 +50,38 @@ describe('karmaProject', () => {
expect(tree.exists('/libs/lib1/karma.conf.js')).toBeTruthy();
expect(tree.exists('/libs/lib1/tsconfig.spec.json')).toBeTruthy();
expect(
tree.read('/libs/lib1/tsconfig.spec.json', 'utf-8')
).toMatchSnapshot();
expect(tree.exists('/libs/lib1/src/test.ts')).toBeTruthy();
expect(tree.exists('karma.conf.js')).toBeTruthy();
});
it('should generate files and not add polyfills if it is using ng v15 style polyfills', async () => {
expect(tree.exists('karma.conf.js')).toBeFalsy();
await karmaProjectGenerator(tree, { project: 'app1' });
expect(tree.exists('/apps/app1/tsconfig.spec.json')).toBeTruthy();
expect(
tree.read('/apps/app1/tsconfig.spec.json', 'utf-8')
).toMatchSnapshot();
});
it('should generate files and correctly add polyfills if it is using old ng style polyfills', async () => {
tree.write('apps/app1/src/polyfills.ts', 'import zone.js;');
const project = readProjectConfiguration(tree, 'app1');
project.targets.build.options.polyfills = 'apps/app1/src/polyfills.ts';
updateProjectConfiguration(tree, 'app1', project);
expect(tree.exists('karma.conf.js')).toBeFalsy();
await karmaProjectGenerator(tree, { project: 'app1' });
expect(tree.exists('/apps/app1/tsconfig.spec.json')).toBeTruthy();
expect(
tree.read('/apps/app1/tsconfig.spec.json', 'utf-8')
).toMatchSnapshot();
});
it('should create a karma.conf.js', async () => {
await karmaProjectGenerator(tree, { project: 'lib1' });
@@ -121,7 +153,7 @@ describe('karmaProject', () => {
builder: '@angular-devkit/build-angular:karma',
options: {
main: 'apps/app1/src/test.ts',
polyfills: 'apps/app1/src/polyfills.ts',
polyfills: ['zone.js', 'zone.js/testing'],
tsConfig: 'apps/app1/tsconfig.spec.json',
karmaConfig: 'apps/app1/karma.conf.js',
styles: [],
@@ -134,6 +166,49 @@ describe('karmaProject', () => {
it('should create a tsconfig.spec.json', async () => {
await karmaProjectGenerator(tree, { project: 'app1' });
const tsConfig = devkit.readJson(tree, 'apps/app1/tsconfig.spec.json');
expect(tsConfig).toEqual({
extends: './tsconfig.json',
compilerOptions: {
outDir: '../../dist/out-tsc',
types: ['jasmine', 'node'],
},
files: ['src/test.ts'],
include: ['**/*.spec.ts', '**/*.test.ts', '**/*.d.ts'],
});
});
it('should update the workspace config correctly when using old style ng polyfills', async () => {
tree.write('apps/app1/src/polyfills.ts', 'import zone.js;');
const project = readProjectConfiguration(tree, 'app1');
project.targets.build.options.polyfills = 'apps/app1/src/polyfills.ts';
updateProjectConfiguration(tree, 'app1', project);
await karmaProjectGenerator(tree, { project: 'app1' });
const workspaceJson = devkit.readJson(tree, 'workspace.json');
expect(workspaceJson.projects.app1.architect.test).toEqual({
builder: '@angular-devkit/build-angular:karma',
options: {
main: 'apps/app1/src/test.ts',
polyfills: 'apps/app1/src/polyfills.ts',
tsConfig: 'apps/app1/tsconfig.spec.json',
karmaConfig: 'apps/app1/karma.conf.js',
styles: [],
scripts: [],
assets: [],
},
});
});
it('should create a tsconfig.spec.json when using old style ng polyfills', async () => {
tree.write('apps/app1/src/polyfills.ts', 'import zone.js;');
const project = readProjectConfiguration(tree, 'app1');
project.targets.build.options.polyfills = 'apps/app1/src/polyfills.ts';
updateProjectConfiguration(tree, 'app1', project);
await karmaProjectGenerator(tree, { project: 'app1' });
const tsConfig = devkit.readJson(tree, 'apps/app1/tsconfig.spec.json');
expect(tsConfig).toEqual({
extends: './tsconfig.json',
@@ -24,8 +24,19 @@ export function updateTsConfigs(tree: Tree, project: string): void {
}
);
const extraFiles =
projectConfig.projectType === 'library' ? [] : ['src/polyfills.ts'];
let extraFiles: string[] = [];
if (
projectConfig.projectType == 'application' &&
projectConfig.targets.build?.options?.polyfills &&
typeof projectConfig.targets.build.options.polyfills === 'string'
) {
let polyfillsPath = projectConfig.targets.build.options.polyfills;
polyfillsPath = polyfillsPath.startsWith(projectConfig.root)
? polyfillsPath.replace(`${projectConfig.root}/`, '')
: polyfillsPath;
extraFiles = [polyfillsPath];
}
return updateJson(
tree,
joinPathFragments(projectConfig.root, 'tsconfig.spec.json'),
@@ -17,9 +17,13 @@ export function updateWorkspaceConfig(tree: Tree, project: string): void {
};
if (projectConfig.projectType === 'application') {
const polyfills = projectConfig.targets.build?.options?.polyfills;
let polyfillsPath =
polyfills && typeof polyfills === 'string' ? polyfills : undefined;
projectConfig.targets.test.options = {
...projectConfig.targets.test.options,
polyfills: joinPathFragments(projectConfig.sourceRoot, 'polyfills.ts'),
polyfills: polyfillsPath ?? ['zone.js', 'zone.js/testing'],
styles: [],
scripts: [],
assets: [],
@@ -9,12 +9,6 @@ Object {
"sourceMap": true,
},
"production": Object {
"fileReplacements": Array [
Object {
"replace": "apps/app1/src/environments/environment.ts",
"with": "apps/app1/src/environments/environment.prod.ts",
},
],
"outputHashing": "media",
},
},
@@ -22,7 +16,7 @@ Object {
"executor": "@angular-devkit/build-angular:server",
"options": Object {
"main": "apps/app1/server.ts",
"outputPath": "dist/apps/apps/app1/server",
"outputPath": "dist/apps/app1/server",
"tsConfig": "apps/app1/tsconfig.server.json",
},
}
@@ -90,3 +84,31 @@ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
export * from './src/main.server';"
`;
exports[`setupSSR should use fileReplacements if they already exist 1`] = `
Object {
"configurations": Object {
"development": Object {
"extractLicenses": false,
"optimization": false,
"sourceMap": true,
},
"production": Object {
"fileReplacements": Array [
Object {
"replace": "apps/app1/src/environments/environment.ts",
"with": "apps/app1/src/environments/environment.prod.ts",
},
],
"outputHashing": "media",
},
},
"defaultConfiguration": "production",
"executor": "@angular-devkit/build-angular:server",
"options": Object {
"main": "apps/app1/server.ts",
"outputPath": "dist/apps/app1/server",
"tsConfig": "apps/app1/tsconfig.server.json",
},
}
`;
@@ -7,13 +7,5 @@
*/
import '@angular/platform-server/init';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
export { <%= rootModuleClassName %> } from './app/<%= rootModuleFileName.slice(0, -3) %>';
export { renderModule } from '@angular/platform-server';
@@ -1,12 +1,6 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
function bootstrap() {
platformBrowserDynamic()
@@ -11,28 +11,22 @@ export function updateProjectConfig(tree: Tree, schema: Schema) {
projectConfig.targets.build.options.outputPath = `dist/apps/${schema.project}/browser`;
const buildTargetFileReplacements =
projectConfig.targets.build.configurations?.production?.fileReplacements;
projectConfig.targets.server = {
executor: '@angular-devkit/build-angular:server',
options: {
outputPath: `dist/apps/${projectConfig.root}/server`,
outputPath: `dist/${projectConfig.root}/server`,
main: joinPathFragments(projectConfig.root, schema.serverFileName),
tsConfig: joinPathFragments(projectConfig.root, 'tsconfig.server.json'),
},
configurations: {
production: {
outputHashing: 'media',
fileReplacements: [
{
replace: joinPathFragments(
projectConfig.sourceRoot,
'environments/environment.ts'
),
with: joinPathFragments(
projectConfig.sourceRoot,
'environments/environment.prod.ts'
),
},
],
...(buildTargetFileReplacements
? { fileReplacements: buildTargetFileReplacements }
: {}),
},
development: {
optimization: false,
@@ -1,4 +1,8 @@
import { readJson, readProjectConfiguration } from '@nrwl/devkit';
import {
readJson,
readProjectConfiguration,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { PackageJson } from 'nx/src/utils/package-json';
import { angularVersion, ngUniversalVersion } from '../../utils/versions';
@@ -34,27 +38,13 @@ describe('setupSSR', () => {
*/
import '@angular/platform-server/init';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
export { AppServerModule } from './app/app.server.module';
export { renderModule } from '@angular/platform-server';"
`);
expect(tree.read('apps/app1/src/main.ts', 'utf-8')).toMatchInlineSnapshot(`
"import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
"import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
function bootstrap() {
platformBrowserDynamic()
@@ -140,4 +130,32 @@ describe('setupSSR', () => {
expect(packageJson.devDependencies[dep]).toEqual(version);
}
});
it('should use fileReplacements if they already exist', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
await applicationGenerator(tree, {
name: 'app1',
});
tree.write('apps/app1/src/environments/environment.ts', '');
tree.write('apps/app1/src/environments/environment.prod.ts', '');
const project = readProjectConfiguration(tree, 'app1');
project.targets.build.configurations.production.fileReplacements = [
{
replace: 'apps/app1/src/environments/environment.ts',
with: 'apps/app1/src/environments/environment.prod.ts',
},
];
updateProjectConfiguration(tree, 'app1', project);
// ACT
await setupSsr(tree, { project: 'app1' });
// ASSERT
expect(
readProjectConfiguration(tree, 'app1').targets.server
).toMatchSnapshot();
});
});
@@ -16,6 +16,8 @@ function updateTarget(tree: Tree, tsconfigPath: string) {
export default async function updateTypescriptTarget(tree: Tree) {
const projects = getProjects(tree);
for (const [, project] of projects) {
if (!project.targets) continue;
for (const [, target] of Object.entries(project.targets)) {
// Update all other known CLI builders that use a tsconfig
const tsConfigs = [
@@ -1,4 +1,3 @@
import axios from 'axios';
import { isCI } from './output';
export class PromptMessages {
@@ -56,7 +55,8 @@ export async function recordStat(opts: {
console.log(`Record stat. Major: ${major}`);
}
if (major < 10 || major > 15) return; // test version, skip it
await axios
const axios = require('axios');
await (axios['default'] ?? axios)
.create({
baseURL: 'https://cloud.nx.app',
timeout: 400,
@@ -25,8 +25,8 @@ exports[`Update .lib.swcrc exclude should update the exclude pattern 1`] = `
\\"sourceMaps\\": true,
\\"exclude\\": [
\\"jest.config.ts\\",
\\".*.spec.tsx?$\\",
\\".*.test.tsx?$\\",
\\".*\\\\\\\\.spec.tsx?$\\",
\\".*\\\\\\\\.test.tsx?$\\",
\\"./src/jest-setup.ts$\\",
\\"./**/jest-setup.ts$\\",
\\".*.js$\\"
+2 -2
View File
@@ -5,8 +5,8 @@ import { join } from 'path';
export const defaultExclude = [
'jest.config.ts',
'.*.spec.tsx?$',
'.*.test.tsx?$',
'.*\\.spec.tsx?$',
'.*\\.test.tsx?$',
'./src/jest-setup.ts$',
'./**/jest-setup.ts$',
'.*.js$',
@@ -126,7 +126,6 @@
},
"reportUnusedDisableDirectives": {
"type": "string",
"default": "off",
"enum": ["off", "warn", "error"],
"description": "The equivalent of the `--report-unused-disable-directives` flag on the ESLint CLI."
}
@@ -156,5 +156,15 @@ describe('eslint-utils', () => {
useEslintrc: true,
});
});
it('should create a ESLint instance with no "reportUnusedDisableDirectives" if it is undefined', async () => {
await lint(undefined, {});
expect(ESLint).toHaveBeenCalledWith(
expect.objectContaining({
reportUnusedDisableDirectives: undefined,
})
);
});
});
});
@@ -17,8 +17,8 @@ const latestVersionWithOldFlag = '13.8.3';
// is already supported
const nxAngularVersionMap: Record<number, { range: string; max?: string }> = {
13: { range: '>= 13.2.0 < 14.2.0', max: '~14.1.0' },
14: { range: '>= 14.2.0' },
15: { range: '>= 15.0.0' },
14: { range: '>= 14.2.0 < 15.2.0', max: '~15.1.0' },
15: { range: '>= 15.2.0' },
};
// latest major version of Angular that is compatible with Nx, based on the map above
const latestCompatibleAngularMajorVersion = Math.max(
+4
View File
@@ -38,6 +38,10 @@ export function withNx(
nextConfig = {} as WithNxOptions,
context: WithNxContext = getWithNxContext()
): NextConfig {
// If `next-compose-plugins` is used, the context argument is invalid.
if (!context.libsDir || !context.workspaceRoot) {
context = getWithNxContext();
}
const userWebpack = nextConfig.webpack || ((x) => x);
const { nx, ...validNextConfig } = nextConfig;
return {
@@ -73,6 +73,10 @@ export function addMigrationJsonChecks(
options.projectName
);
if (!projectIsEsLintEnabled(projectConfiguration)) {
return;
}
const [eslintTarget, eslintTargetConfiguration] =
getEsLintOptions(projectConfiguration);
+1
View File
@@ -68,6 +68,7 @@ function isKnownCommand() {
'affected:dep-graph',
'format',
'workspace-schematic',
'connect-to-nx-cloud',
'clear-cache',
'help',
];
+3 -3
View File
@@ -36,6 +36,7 @@
"@yarnpkg/lockfile": "^1.1.0",
"@yarnpkg/parsers": "^3.0.0-rc.18",
"@zkochan/js-yaml": "0.0.6",
"axios": "^1.0.0",
"chalk": "4.1.0",
"chokidar": "^3.5.1",
"cli-cursor": "3.1.0",
@@ -49,6 +50,7 @@
"fs-extra": "^10.1.0",
"glob": "7.1.4",
"ignore": "^5.0.4",
"js-yaml": "4.1.0",
"jsonc-parser": "3.2.0",
"minimatch": "3.0.5",
"npm-run-path": "^4.0.1",
@@ -62,9 +64,7 @@
"tslib": "^2.3.0",
"v8-compile-cache": "2.3.0",
"yargs": "^17.6.2",
"yargs-parser": "21.1.1",
"js-yaml": "4.1.0",
"axios": "^1.0.0"
"yargs-parser": "21.1.1"
},
"peerDependencies": {
"@swc-node/register": "^1.4.2",
+33 -18
View File
@@ -58,7 +58,9 @@ export const commandsObject = yargs
describe: 'Run target for multiple listed projects',
builder: (yargs) =>
linkToNxDevAndExamples(
withRunManyOptions(withOutputStyleOption(withTargetOption(yargs))),
withRunManyOptions(
withOutputStyleOption(withTargetAndConfigurationOption(yargs))
),
'run-many'
),
handler: async (args) =>
@@ -70,7 +72,9 @@ export const commandsObject = yargs
builder: (yargs) =>
linkToNxDevAndExamples(
withAffectedOptions(
withRunOptions(withOutputStyleOption(withTargetOption(yargs)))
withRunOptions(
withOutputStyleOption(withTargetAndConfigurationOption(yargs))
)
),
'affected'
),
@@ -190,7 +194,10 @@ export const commandsObject = yargs
builder: (yargs) =>
linkToNxDevAndExamples(
withAffectedOptions(
withTargetOption(withPrintAffectedOptions(yargs), false)
withTargetAndConfigurationOption(
withPrintAffectedOptions(yargs),
false
)
),
'print-affected'
),
@@ -434,12 +441,6 @@ function withRunOptions(yargs: yargs.Argv): yargs.Argv {
describe: 'This is the name of the tasks runner configured in nx.json',
type: 'string',
})
.options('configuration', {
describe:
'This is the configuration to use when performing tasks on projects',
type: 'string',
alias: 'c',
})
.option('prod', {
describe: 'Use the production configuration',
type: 'boolean',
@@ -617,14 +618,24 @@ function withOutputStyleOption(
});
}
function withTargetOption(yargs: yargs.Argv, demandOption = true): yargs.Argv {
return yargs.option('target', {
describe: 'Task to run for affected projects',
type: 'string',
requiresArg: true,
demandOption,
global: false,
});
function withTargetAndConfigurationOption(
yargs: yargs.Argv,
demandOption = true
): yargs.Argv {
return yargs
.option('target', {
describe: 'Task to run for affected projects',
type: 'string',
requiresArg: true,
demandOption,
global: false,
})
.options('configuration', {
describe:
'This is the configuration to use when performing tasks on projects',
type: 'string',
alias: 'c',
});
}
function withNewOptions(yargs: yargs.Argv) {
@@ -683,7 +694,7 @@ function withRunOneOptions(yargs: yargs.Argv) {
);
const res = withRunOptions(
withOutputStyleOption(withTargetOption(yargs, false), [
withOutputStyleOption(withTargetAndConfigurationOption(yargs, false), [
'dynamic',
'static',
'stream',
@@ -699,6 +710,10 @@ function withRunOneOptions(yargs: yargs.Argv) {
.option('project', {
describe: 'Target project',
type: 'string',
})
.option('help', {
describe: 'Show Help',
type: 'boolean',
});
if (executorShouldShowHelp) {
@@ -375,8 +375,8 @@ function addProjectToWorkspaceJson(
// update the project.json file
writeJson(tree, projectConfigFile, {
...jsonSchema,
name: mode === 'create' ? projectName : project.name ?? projectName,
...jsonSchema,
...project,
root: undefined,
});
@@ -1,5 +1,5 @@
import { readFileSync, writeFileSync } from 'fs-extra';
import { detectPackageManager, PackageManager } from '../package-manager';
import { detectPackageManager, PackageManager } from '../utils/package-manager';
import {
parseYarnLockFile,
pruneYarnLockFile,
@@ -19,13 +19,13 @@ import {
transitiveDependencyPnpmLookup,
} from './pnpm';
import { LockFileData } from './lock-file-type';
import { workspaceRoot } from '../workspace-root';
import { workspaceRoot } from '../utils/workspace-root';
import { join } from 'path';
import { hashExternalNodes, hashString, mapExternalNodes } from './utils';
import {
ProjectGraph,
ProjectGraphExternalNode,
} from '../../config/project-graph';
} from '../config/project-graph';
import { existsSync } from 'fs';
const YARN_LOCK_PATH = join(workspaceRoot, 'yarn.lock');
@@ -15,7 +15,6 @@ import {
lockFileV2YargsAndDevkitOnly,
} from './__fixtures__/npm.lock';
import { vol } from 'memfs';
import { readJsonFile } from '../fileutils';
jest.mock('fs', () => require('memfs').fs);
@@ -1,9 +1,9 @@
import { existsSync } from 'fs';
import { satisfies } from 'semver';
import { readJsonFile } from '../fileutils';
import { output } from '../output';
import { joinPathFragments } from '../path';
import { workspaceRoot } from '../workspace-root';
import { readJsonFile } from '../utils/fileutils';
import { output } from '../utils/output';
import { joinPathFragments } from '../utils/path';
import { workspaceRoot } from '../utils/workspace-root';
import { LockFileData, PackageDependency } from './lock-file-type';
import {
sortObject,
@@ -1,15 +1,15 @@
import { defaultHashing } from '../../hasher/hashing-impl';
import { defaultHashing } from '../hasher/hashing-impl';
import {
LockFileData,
PackageDependency,
PackageVersions,
} from './lock-file-type';
import { workspaceRoot } from '../workspace-root';
import { workspaceRoot } from '../utils/workspace-root';
import { existsSync, readFileSync } from 'fs';
import {
ProjectGraph,
ProjectGraphExternalNode,
} from '../../config/project-graph';
} from '../config/project-graph';
/**
* Simple sort function to ensure keys are ordered alphabetically
@@ -25,7 +25,6 @@ import { getRootTsConfigPath } from '../utils/typescript';
import {
ProjectFileMap,
ProjectGraph,
ProjectGraphExternalNode,
ProjectGraphProcessorContext,
} from '../config/project-graph';
import { readJsonFile } from '../utils/fileutils';
@@ -45,7 +44,7 @@ import {
lockFileHash,
mapLockFileDataToPartialGraph,
parseLockFile,
} from '../utils/lock-file/lock-file';
} from '../lock-file/lock-file';
export async function buildProjectGraph() {
const projectConfigurations = readAllWorkspaceConfiguration();
+2 -2
View File
@@ -1,4 +1,3 @@
import axios from 'axios';
import { isCI } from './is-ci';
export class PromptMessages {
@@ -56,7 +55,8 @@ export async function recordStat(opts: {
console.log(`Record stat. Major: ${major}`);
}
if (major < 10 || major > 15) return; // test version, skip it
await axios
const axios = require('axios');
await (axios['default'] ?? axios)
.create({
baseURL: 'https://cloud.nx.app',
timeout: 400,
+41 -2
View File
@@ -1460,7 +1460,7 @@ describe('params', () => {
]);
});
it('should use an multiselect prompt for x-prompts with items', () => {
it('should use a multiselect prompt for x-prompts with items', () => {
const prompts = getPromptsForSchema(
{},
{
@@ -1492,7 +1492,46 @@ describe('params', () => {
]);
});
it('should use an multiselect prompt for x-prompts with items', () => {
it('should use a multiselect prompt for array properties', () => {
const prompts = getPromptsForSchema(
{},
{
properties: {
pets: {
type: 'array',
'x-prompt': {
type: 'list',
message: 'What kind of pets do you have?',
items: [
{ label: 'Cat', value: 'cat' },
{ label: 'Dog', value: 'dog' },
{ label: 'Fish', value: 'fish' },
],
},
},
},
},
{
version: 2,
projects: {},
}
);
expect(prompts).toEqual([
{
type: 'multiselect',
name: 'pets',
message: 'What kind of pets do you have?',
choices: [
{ message: 'Cat', name: 'cat' },
{ message: 'Dog', name: 'dog' },
{ message: 'Fish', name: 'fish' },
],
},
]);
});
it('should use a multiselect prompt for x-prompts with items', () => {
const prompts = getPromptsForSchema(
{},
{
+4 -3
View File
@@ -770,9 +770,10 @@ export function getPromptsForSchema(
question.type = 'confirm';
} else if (v['x-prompt'].items) {
question.message = v['x-prompt'].message;
question.type = v['x-prompt'].multiselect
? 'multiselect'
: 'autocomplete';
question.type =
v['x-prompt'].multiselect || v.type === 'array'
? 'multiselect'
: 'autocomplete';
question.choices =
v['x-prompt'].items &&
v['x-prompt'].items.map((item) => {
@@ -190,7 +190,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../src/**/*.stories.ts\\",
@@ -252,7 +251,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../src/**/*.stories.ts\\",
@@ -321,7 +319,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../components/**/*.stories.ts\\",
@@ -383,7 +380,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../src/**/*.stories.ts\\",
@@ -445,7 +441,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../src/**/*.stories.ts\\",
@@ -507,7 +502,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../src/**/*.stories.ts\\",
@@ -568,7 +562,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../src/**/*.stories.ts\\",
@@ -628,7 +621,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../src/**/*.stories.ts\\",
@@ -695,7 +687,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../components/**/*.stories.ts\\",
@@ -755,7 +746,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../src/**/*.stories.ts\\",
@@ -815,7 +805,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../src/**/*.stories.ts\\",
@@ -875,7 +864,6 @@ exports[`@nrwl/storybook:configuration for other types of projects - Next.js and
\\"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts\\",
\\"../../../node_modules/@nrwl/react/typings/image.d.ts\\"
],
\\"exclude\\": [\\"../**/*.spec.ts\\" , \\"../**/*.spec.js\\", \\"../**/*.spec.tsx\\", \\"../**/*.spec.jsx\\"],
\\"include\\": [
\\"../src/**/*.stories.ts\\",
@@ -9,7 +9,6 @@
"<%= offsetFromRoot %>../node_modules/@nrwl/react/typings/cssmodule.d.ts",
"<%= offsetFromRoot %>../node_modules/@nrwl/react/typings/image.d.ts"
],<% } %>
<% if(uiFramework === '@storybook/angular' && projectType === 'application') { %>"files": ["../src/polyfills.ts"],<% } %>
"exclude": ["../**/*.spec.ts" <% if(uiFramework === '@storybook/react') { %>, "../**/*.spec.js", "../**/*.spec.tsx", "../**/*.spec.jsx"<% } %>],
"include": [<% if(uiFramework === '@storybook/angular' && projectType === 'library') { %>
"../**/*.stories.ts",
@@ -9,7 +9,6 @@
"<%= offsetFromRoot %>../node_modules/@nrwl/react/typings/cssmodule.d.ts",
"<%= offsetFromRoot %>../node_modules/@nrwl/react/typings/image.d.ts"
],<% } %>
<% if(uiFramework === '@storybook/angular' && projectType === 'application') { %>"files": ["../src/polyfills.ts"],<% } %>
"exclude": ["../**/*.spec.ts" <% if(uiFramework === '@storybook/react') { %>, "../**/*.spec.js", "../**/*.spec.tsx", "../**/*.spec.jsx"<% } %>],
"include": [<% if(uiFramework === '@storybook/angular' && projectType === 'library') { %>
"../**/*.stories.ts",
@@ -1,5 +1,7 @@
// source: https://github.com/Myrmod/vitejs-theming/blob/master/build-plugins/rollup/replace-files.js
import { resolve } from 'path';
/**
* @function replaceFiles
* @param {FileReplacement[]} replacements
@@ -12,10 +14,21 @@ export default function replaceFiles(replacements: FileReplacement[]) {
return {
name: 'rollup-plugin-replace-files',
enforce: 'pre',
async resolveId(source, importer) {
const resolved = await this.resolve(source, importer, { skipSelf: true });
const foundReplace = replacements.find(
(replacement) => replacement.replace === resolved?.id
async resolveId(source, importer, options) {
const resolved = await this.resolve(source, importer, {
...options,
skipSelf: true,
});
/**
* The reason we're using endsWith here is because the resolved id
* will be the absolute path to the file. We want to check if the
* file ends with the file we're trying to replace, which will be essentially
* the path from the root of our workspace.
*/
const foundReplace = replacements.find((replacement) =>
resolved?.id?.endsWith(replacement.replace)
);
if (foundReplace) {
console.info(
@@ -36,14 +36,6 @@ function checkDependenciesInstalled(host: Tree, schema: Schema) {
devDependencies['@vitejs/plugin-react'] = vitePluginReactVersion;
}
if (schema.uiFramework === 'vue3') {
devDependencies['@vitejs/plugin-vue'] = vitePluginReactVersion;
}
if (schema.uiFramework === 'vue3-jsx') {
devDependencies['@vitejs/plugin-vue-jsx'] = vitePluginReactVersion;
}
return addDependenciesToPackageJson(host, dependencies, devDependencies);
}
+1 -1
View File
@@ -1,3 +1,3 @@
export interface Schema {
uiFramework: 'react' | 'vue3' | 'vue3-jsx';
uiFramework: 'react' | 'none';
}
@@ -8,7 +8,7 @@
"uiFramework": {
"type": "string",
"description": "UI Framework to use for Vite.",
"enum": ["react", "vue3", "vue3-jsx"],
"enum": ["react", "none"],
"default": "react",
"x-prompt": "What UI framework plugin should Vite use?"
}
+1 -3
View File
@@ -41,6 +41,7 @@ export async function getBuildConfig(
context.root,
projectRoot
),
plugins: [replaceFiles(options.fileReplacements)],
build: getViteBuildOptions(
options as ViteDevServerExecutorOptions & ViteBuildExecutorOptions,
projectRoot
@@ -144,9 +145,6 @@ export function getViteBuildOptions(
commonjsOptions: {
transformMixedEsModules: true,
},
rollupOptions: {
plugins: [replaceFiles(options.fileReplacements)],
},
};
buildOptions = {
@@ -35,7 +35,10 @@ export function createPackageJson(
const rootPackageJson = readJsonFile(`${options.root}/package.json`);
Object.entries(npmDeps).forEach(([packageName, version]) => {
if (rootPackageJson.devDependencies?.[packageName]) {
if (
rootPackageJson.devDependencies?.[packageName] &&
!packageJson.dependencies[packageName]
) {
packageJson.devDependencies[packageName] = version;
} else {
packageJson.dependencies[packageName] = version;
@@ -99,8 +102,12 @@ function recursivelyCollectPeerDependencies(
.map((dependency) => graph.externalNodes[dependency])
.filter(Boolean)
.forEach((node) => {
list[node.data.packageName] = node.data.version;
recursivelyCollectPeerDependencies(node.name, graph, list, seen);
if (
!packageJson.peerDependenciesMeta?.[node.data.packageName]?.optional
) {
list[node.data.packageName] = node.data.version;
recursivelyCollectPeerDependencies(node.name, graph, list, seen);
}
});
return list;
} catch (e) {
-196
View File
@@ -1,196 +0,0 @@
/*
* This script checks if new versions of node modules are available.
* It uses naming conventions to transform constants to matching node module name.
*
* Usage:
* yarn check-versions [file|package]
*
* Positional arg:
* - [file]: relative or absolute file path to the versions file.
*
* Example:
* yarn check-versions react
*/
import { join, relative } from 'path';
import { gt } from 'semver';
import { readJsonSync, writeJsonSync } from 'fs-extra';
import * as chalk from 'chalk';
import { dasherize } from '../packages/workspace/src/utils/strings';
import * as glob from 'glob';
import { execSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
const root = join(__dirname, '..');
const excluded = ['nxVersion'];
const scoped = [
'babel',
'emotion',
'reduxjs',
'swc',
'testing-library',
'types',
];
try {
const files = process.argv[2]
? [normalize(process.argv[2])]
: glob.sync('packages/**/*/versions.ts').map((x) => relative(root, x));
checkFiles(files);
} catch (e) {
console.log(chalk.red(e.message));
process.exitCode = 1;
}
function normalize(x: string) {
if (x.endsWith('.ts')) {
return x;
} else {
return join('packages', x, 'src/utils/versions.ts');
}
}
// -----------------------------------------------------------------------------
function checkFiles(files: string[]) {
console.log(chalk.blue(`Checking versions in the following files...\n`));
console.log(` - ${files.join('\n - ')}\n`);
const maxFileNameLength = Math.max(...files.map((f) => f.length));
let hasError = false;
files.forEach((f) => {
const projectRoot = f.split('/src/')[0];
const migrationsPath = join(projectRoot, 'migrations.json');
const migrationsJson = readJsonSync(migrationsPath);
let versionsContent = readFileSync(f).toString();
const versions = getVersions(f);
const npmPackages = getPackages(versions);
const results = npmPackages.map(([p, v, o]) => getVersionData(p, v, o));
const logContext = `${f.padEnd(maxFileNameLength)}`;
const packageUpdates = {};
results.forEach((r) => {
if (r.outdated) {
console.log(
`${logContext}${chalk.bold(
r.package
)} has new version ${chalk.bold(r.latest)} (current: ${r.prev})`
);
versionsContent = versionsContent.replace(
`${r.variable} = '${r.prev}'`,
`${r.variable} = '${r.latest}'`
);
packageUpdates[r.package] = {
version: r.latest,
alwaysAddToPackageJson: false,
};
}
if (r.invalid) {
hasError = true;
console.log(
`${logContext} ⚠️ ${chalk.bold(r.package)} has an invalid version (${
r.prev
}) specified. Latest is ${r.latest}.`
);
}
});
if (Object.keys(packageUpdates).length > 0) {
migrationsJson.packageJsonUpdates['x.y.z'] = {
version: 'x.y.z',
packages: packageUpdates,
};
writeFileSync(f, versionsContent);
writeJsonSync(migrationsPath, migrationsJson, { spaces: 2 });
}
});
if (hasError) {
throw new Error('Invalid versions of packages found (please see above).');
}
}
function getVersions(path: string) {
const versionsPath =
path.startsWith('.') || path.startsWith('packages')
? join(__dirname, '..', path)
: path;
try {
return require(versionsPath);
} catch {
throw new Error(`Could not load ${path}. Please make sure it is valid.`);
}
}
function getPackages(versions: Record<string, string>): string[][] {
return Object.entries(versions).reduce((acc, [name, version]) => {
if (!excluded.includes(name)) {
const npmName = getNpmName(name);
acc.push([npmName, version, name]);
}
return acc;
}, [] as string[][]);
}
function getNpmName(name: string): string {
const dashedName = dasherize(name.replace(/Version$/, ''));
const scope = scoped.find((s) => dashedName.startsWith(`${s}-`));
if (scope) {
const rest = dashedName.split(`${scope}-`)[1];
return `@${scope}/${rest}`;
} else {
return dashedName;
}
}
function getVersionData(
p: string,
v: string,
o: string
): {
variable: string;
package: string;
outdated: boolean;
invalid: boolean;
latest: string;
prev?: string;
} {
try {
const latest = JSON.parse(
execSync(`npm view ${p} version --json --silent`, {
stdio: ['ignore'],
}).toString('utf-8')
);
if (gt(latest, v)) {
return {
variable: o,
package: p,
outdated: true,
invalid: false,
latest,
prev: v,
};
}
if (gt(v, latest)) {
return {
variable: o,
package: p,
outdated: false,
invalid: true,
latest,
prev: v,
};
}
} catch {
// ignored
}
return {
variable: o,
package: p,
outdated: false,
invalid: false,
latest: v,
};
}