@nx/js 0.0.0-pr-22179-271588f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +68 -0
- package/babel.d.ts +13 -0
- package/babel.js +91 -0
- package/executors.json +32 -0
- package/generators.json +46 -0
- package/migrations.json +159 -0
- package/package.json +76 -0
- package/plugins/jest/local-registry.d.ts +1 -0
- package/plugins/jest/local-registry.js +4 -0
- package/src/executors/node/lib/kill-tree.d.ts +2 -0
- package/src/executors/node/lib/kill-tree.js +114 -0
- package/src/executors/node/node-with-require-overrides.d.ts +7 -0
- package/src/executors/node/node-with-require-overrides.js +21 -0
- package/src/executors/node/node.impl.d.ts +7 -0
- package/src/executors/node/node.impl.js +288 -0
- package/src/executors/node/schema.d.ts +18 -0
- package/src/executors/node/schema.json +92 -0
- package/src/executors/release-publish/format-bytes.d.ts +1 -0
- package/src/executors/release-publish/format-bytes.js +28 -0
- package/src/executors/release-publish/log-tar.d.ts +1 -0
- package/src/executors/release-publish/log-tar.js +68 -0
- package/src/executors/release-publish/release-publish.impl.d.ts +5 -0
- package/src/executors/release-publish/release-publish.impl.js +198 -0
- package/src/executors/release-publish/schema.d.ts +8 -0
- package/src/executors/release-publish/schema.json +26 -0
- package/src/executors/swc/schema.json +154 -0
- package/src/executors/swc/swc.impl.d.ts +10 -0
- package/src/executors/swc/swc.impl.js +149 -0
- package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +5 -0
- package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +62 -0
- package/src/executors/tsc/lib/batch/index.d.ts +4 -0
- package/src/executors/tsc/lib/batch/index.js +7 -0
- package/src/executors/tsc/lib/batch/normalize-tasks-options.d.ts +3 -0
- package/src/executors/tsc/lib/batch/normalize-tasks-options.js +14 -0
- package/src/executors/tsc/lib/batch/types.d.ts +17 -0
- package/src/executors/tsc/lib/batch/types.js +2 -0
- package/src/executors/tsc/lib/batch/watch.d.ts +3 -0
- package/src/executors/tsc/lib/batch/watch.js +56 -0
- package/src/executors/tsc/lib/get-custom-transformers-factory.d.ts +3 -0
- package/src/executors/tsc/lib/get-custom-transformers-factory.js +13 -0
- package/src/executors/tsc/lib/get-task-options.d.ts +3 -0
- package/src/executors/tsc/lib/get-task-options.js +34 -0
- package/src/executors/tsc/lib/get-tsconfig.d.ts +4 -0
- package/src/executors/tsc/lib/get-tsconfig.js +86 -0
- package/src/executors/tsc/lib/index.d.ts +4 -0
- package/src/executors/tsc/lib/index.js +7 -0
- package/src/executors/tsc/lib/normalize-options.d.ts +2 -0
- package/src/executors/tsc/lib/normalize-options.js +39 -0
- package/src/executors/tsc/lib/typescript-compilation.d.ts +29 -0
- package/src/executors/tsc/lib/typescript-compilation.js +203 -0
- package/src/executors/tsc/lib/typescript-diagnostic-reporters.d.ts +3 -0
- package/src/executors/tsc/lib/typescript-diagnostic-reporters.js +37 -0
- package/src/executors/tsc/schema.json +163 -0
- package/src/executors/tsc/tsc.batch-impl.d.ts +5 -0
- package/src/executors/tsc/tsc.batch-impl.js +180 -0
- package/src/executors/tsc/tsc.impl.d.ts +7 -0
- package/src/executors/tsc/tsc.impl.js +97 -0
- package/src/executors/verdaccio/schema.d.ts +7 -0
- package/src/executors/verdaccio/schema.json +35 -0
- package/src/executors/verdaccio/verdaccio.impl.d.ts +12 -0
- package/src/executors/verdaccio/verdaccio.impl.js +220 -0
- package/src/generators/convert-to-swc/convert-to-swc.d.ts +4 -0
- package/src/generators/convert-to-swc/convert-to-swc.js +59 -0
- package/src/generators/convert-to-swc/schema.d.ts +4 -0
- package/src/generators/convert-to-swc/schema.json +36 -0
- package/src/generators/init/files/__fileName__ +20 -0
- package/src/generators/init/init.d.ts +4 -0
- package/src/generators/init/init.js +114 -0
- package/src/generators/init/schema.d.ts +7 -0
- package/src/generators/init/schema.json +36 -0
- package/src/generators/library/files/jest-config/jest.config.__ext__ +30 -0
- package/src/generators/library/files/lib/src/index.ts__tmpl__ +1 -0
- package/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ +7 -0
- package/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ +3 -0
- package/src/generators/library/files/lib/tsconfig.lib.json__tmpl__ +14 -0
- package/src/generators/library/files/readme/README.md +19 -0
- package/src/generators/library/library.d.ts +16 -0
- package/src/generators/library/library.js +751 -0
- package/src/generators/library/schema.json +151 -0
- package/src/generators/release-version/release-version.d.ts +5 -0
- package/src/generators/release-version/release-version.js +390 -0
- package/src/generators/release-version/schema.d.ts +1 -0
- package/src/generators/release-version/schema.json +67 -0
- package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.d.ts +16 -0
- package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.js +40 -0
- package/src/generators/release-version/utils/package.d.ts +12 -0
- package/src/generators/release-version/utils/package.js +34 -0
- package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +12 -0
- package/src/generators/release-version/utils/resolve-local-package-dependencies.js +78 -0
- package/src/generators/release-version/utils/resolve-version-spec.d.ts +1 -0
- package/src/generators/release-version/utils/resolve-version-spec.js +29 -0
- package/src/generators/release-version/utils/update-lock-file.d.ts +5 -0
- package/src/generators/release-version/utils/update-lock-file.js +105 -0
- package/src/generators/setup-build/generator.d.ts +4 -0
- package/src/generators/setup-build/generator.js +142 -0
- package/src/generators/setup-build/schema.d.ts +7 -0
- package/src/generators/setup-build/schema.json +42 -0
- package/src/generators/setup-verdaccio/files/config.yml +28 -0
- package/src/generators/setup-verdaccio/generator.d.ts +4 -0
- package/src/generators/setup-verdaccio/generator.js +56 -0
- package/src/generators/setup-verdaccio/schema.d.ts +3 -0
- package/src/generators/setup-verdaccio/schema.json +16 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +28 -0
- package/src/internal.d.ts +4 -0
- package/src/internal.js +15 -0
- package/src/migrations/update-15-8-0/rename-swcrc-config.d.ts +2 -0
- package/src/migrations/update-15-8-0/rename-swcrc-config.js +77 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.d.ts +2 -0
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +34 -0
- package/src/migrations/update-16-8-2/update-swcrc.d.ts +2 -0
- package/src/migrations/update-16-8-2/update-swcrc.js +23 -0
- package/src/migrations/update-17-0-0/remove-deprecated-build-options.d.ts +6 -0
- package/src/migrations/update-17-0-0/remove-deprecated-build-options.js +30 -0
- package/src/plugins/jest/start-local-registry.d.ts +12 -0
- package/src/plugins/jest/start-local-registry.js +63 -0
- package/src/plugins/rollup/type-definitions.d.ts +8 -0
- package/src/plugins/rollup/type-definitions.js +48 -0
- package/src/utils/add-babel-inputs.d.ts +3 -0
- package/src/utils/add-babel-inputs.js +23 -0
- package/src/utils/add-local-registry-scripts.d.ts +5 -0
- package/src/utils/add-local-registry-scripts.js +77 -0
- package/src/utils/assets/assets.d.ts +10 -0
- package/src/utils/assets/assets.js +36 -0
- package/src/utils/assets/copy-assets-handler.d.ts +32 -0
- package/src/utils/assets/copy-assets-handler.js +154 -0
- package/src/utils/assets/index.d.ts +16 -0
- package/src/utils/assets/index.js +27 -0
- package/src/utils/buildable-libs-utils.d.ts +43 -0
- package/src/utils/buildable-libs-utils.js +375 -0
- package/src/utils/check-dependencies.d.ts +8 -0
- package/src/utils/check-dependencies.js +23 -0
- package/src/utils/code-frames/highlight.d.ts +1 -0
- package/src/utils/code-frames/highlight.js +86 -0
- package/src/utils/code-frames/identifiers.d.ts +5 -0
- package/src/utils/code-frames/identifiers.js +52 -0
- package/src/utils/compiler-helper-dependency.d.ts +18 -0
- package/src/utils/compiler-helper-dependency.js +120 -0
- package/src/utils/find-npm-dependencies.d.ts +9 -0
- package/src/utils/find-npm-dependencies.js +140 -0
- package/src/utils/generate-globs.d.ts +6 -0
- package/src/utils/generate-globs.js +80 -0
- package/src/utils/get-import-path.d.ts +5 -0
- package/src/utils/get-import-path.js +14 -0
- package/src/utils/get-main-file-dir.d.ts +1 -0
- package/src/utils/get-main-file-dir.js +11 -0
- package/src/utils/inline.d.ts +19 -0
- package/src/utils/inline.js +210 -0
- package/src/utils/package-json/create-entry-points.d.ts +1 -0
- package/src/utils/package-json/create-entry-points.js +23 -0
- package/src/utils/package-json/get-npm-scope.d.ts +5 -0
- package/src/utils/package-json/get-npm-scope.js +16 -0
- package/src/utils/package-json/index.d.ts +13 -0
- package/src/utils/package-json/index.js +30 -0
- package/src/utils/package-json/update-package-json.d.ts +30 -0
- package/src/utils/package-json/update-package-json.js +179 -0
- package/src/utils/prettier.d.ts +6 -0
- package/src/utils/prettier.js +34 -0
- package/src/utils/schema.d.ts +87 -0
- package/src/utils/swc/add-swc-config.d.ts +3 -0
- package/src/utils/swc/add-swc-config.js +41 -0
- package/src/utils/swc/add-swc-dependencies.d.ts +3 -0
- package/src/utils/swc/add-swc-dependencies.js +18 -0
- package/src/utils/swc/compile-swc.d.ts +13 -0
- package/src/utils/swc/compile-swc.js +160 -0
- package/src/utils/swc/get-swcrc-path.d.ts +5 -0
- package/src/utils/swc/get-swcrc-path.js +15 -0
- package/src/utils/swc/inline.d.ts +2 -0
- package/src/utils/swc/inline.js +11 -0
- package/src/utils/typescript/__mocks__/plugin-a.d.ts +1 -0
- package/src/utils/typescript/__mocks__/plugin-a.js +5 -0
- package/src/utils/typescript/__mocks__/plugin-b.d.ts +1 -0
- package/src/utils/typescript/__mocks__/plugin-b.js +5 -0
- package/src/utils/typescript/add-tslib-dependencies.d.ts +2 -0
- package/src/utils/typescript/add-tslib-dependencies.js +11 -0
- package/src/utils/typescript/ast-utils.d.ts +32 -0
- package/src/utils/typescript/ast-utils.js +266 -0
- package/src/utils/typescript/compile-typescript-files.d.ts +10 -0
- package/src/utils/typescript/compile-typescript-files.js +43 -0
- package/src/utils/typescript/create-ts-config.d.ts +18 -0
- package/src/utils/typescript/create-ts-config.js +48 -0
- package/src/utils/typescript/ensure-typescript.d.ts +1 -0
- package/src/utils/typescript/ensure-typescript.js +9 -0
- package/src/utils/typescript/get-source-nodes.d.ts +2 -0
- package/src/utils/typescript/get-source-nodes.js +18 -0
- package/src/utils/typescript/load-ts-transformers.d.ts +5 -0
- package/src/utils/typescript/load-ts-transformers.js +62 -0
- package/src/utils/typescript/print-diagnostics.d.ts +1 -0
- package/src/utils/typescript/print-diagnostics.js +18 -0
- package/src/utils/typescript/run-type-check.d.ts +32 -0
- package/src/utils/typescript/run-type-check.js +128 -0
- package/src/utils/typescript/ts-config.d.ts +9 -0
- package/src/utils/typescript/ts-config.js +85 -0
- package/src/utils/typescript/tsnode-register.d.ts +1 -0
- package/src/utils/typescript/tsnode-register.js +24 -0
- package/src/utils/typescript/types.d.ts +18 -0
- package/src/utils/typescript/types.js +2 -0
- package/src/utils/versions.d.ts +17 -0
- package/src/utils/versions.js +21 -0
- package/src/utils/watch-for-single-file-changes.d.ts +1 -0
- package/src/utils/watch-for-single-file-changes.js +22 -0
|
@@ -0,0 +1,751 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addLint = exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
6
|
+
const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
|
|
7
|
+
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
8
|
+
const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const add_swc_config_1 = require("../../utils/swc/add-swc-config");
|
|
11
|
+
const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
|
|
12
|
+
const create_ts_config_1 = require("../../utils/typescript/create-ts-config");
|
|
13
|
+
const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
14
|
+
const versions_1 = require("../../utils/versions");
|
|
15
|
+
const init_1 = require("../init/init");
|
|
16
|
+
const generator_1 = require("../setup-verdaccio/generator");
|
|
17
|
+
const defaultOutputDirectory = 'dist';
|
|
18
|
+
async function libraryGenerator(tree, schema) {
|
|
19
|
+
return await libraryGeneratorInternal(tree, {
|
|
20
|
+
addPlugin: false,
|
|
21
|
+
// provide a default projectNameAndRootFormat to avoid breaking changes
|
|
22
|
+
// to external generators invoking this one
|
|
23
|
+
projectNameAndRootFormat: 'derived',
|
|
24
|
+
...schema,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.libraryGenerator = libraryGenerator;
|
|
28
|
+
async function libraryGeneratorInternal(tree, schema) {
|
|
29
|
+
const tasks = [];
|
|
30
|
+
tasks.push(await (0, init_1.default)(tree, {
|
|
31
|
+
...schema,
|
|
32
|
+
skipFormat: true,
|
|
33
|
+
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
|
34
|
+
}));
|
|
35
|
+
const options = await normalizeOptions(tree, schema);
|
|
36
|
+
createFiles(tree, options);
|
|
37
|
+
await addProject(tree, options);
|
|
38
|
+
if (!options.skipPackageJson) {
|
|
39
|
+
tasks.push(addProjectDependencies(tree, options));
|
|
40
|
+
}
|
|
41
|
+
if (options.publishable) {
|
|
42
|
+
tasks.push(await (0, generator_1.default)(tree, { ...options, skipFormat: true }));
|
|
43
|
+
}
|
|
44
|
+
if (options.bundler === 'vite') {
|
|
45
|
+
const { viteConfigurationGenerator, createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
46
|
+
const viteTask = await viteConfigurationGenerator(tree, {
|
|
47
|
+
project: options.name,
|
|
48
|
+
newProject: true,
|
|
49
|
+
uiFramework: 'none',
|
|
50
|
+
includeVitest: options.unitTestRunner === 'vitest',
|
|
51
|
+
includeLib: true,
|
|
52
|
+
skipFormat: true,
|
|
53
|
+
testEnvironment: options.testEnvironment,
|
|
54
|
+
addPlugin: options.addPlugin,
|
|
55
|
+
});
|
|
56
|
+
tasks.push(viteTask);
|
|
57
|
+
createOrEditViteConfig(tree, {
|
|
58
|
+
project: options.name,
|
|
59
|
+
includeLib: true,
|
|
60
|
+
includeVitest: options.unitTestRunner === 'vitest',
|
|
61
|
+
testEnvironment: options.testEnvironment,
|
|
62
|
+
}, false);
|
|
63
|
+
}
|
|
64
|
+
if (options.linter !== 'none') {
|
|
65
|
+
const lintCallback = await addLint(tree, options);
|
|
66
|
+
tasks.push(lintCallback);
|
|
67
|
+
}
|
|
68
|
+
if (options.unitTestRunner === 'jest') {
|
|
69
|
+
const jestCallback = await addJest(tree, options);
|
|
70
|
+
tasks.push(jestCallback);
|
|
71
|
+
if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
72
|
+
replaceJestConfig(tree, options);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (options.unitTestRunner === 'vitest' &&
|
|
76
|
+
options.bundler !== 'vite' // Test would have been set up already
|
|
77
|
+
) {
|
|
78
|
+
const { vitestGenerator, createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
79
|
+
const vitestTask = await vitestGenerator(tree, {
|
|
80
|
+
project: options.name,
|
|
81
|
+
uiFramework: 'none',
|
|
82
|
+
coverageProvider: 'v8',
|
|
83
|
+
skipFormat: true,
|
|
84
|
+
testEnvironment: options.testEnvironment,
|
|
85
|
+
});
|
|
86
|
+
tasks.push(vitestTask);
|
|
87
|
+
createOrEditViteConfig(tree, {
|
|
88
|
+
project: options.name,
|
|
89
|
+
includeLib: false,
|
|
90
|
+
includeVitest: true,
|
|
91
|
+
testEnvironment: options.testEnvironment,
|
|
92
|
+
}, true);
|
|
93
|
+
}
|
|
94
|
+
if (!schema.skipTsConfig) {
|
|
95
|
+
(0, ts_config_1.addTsConfigPath)(tree, options.importPath, [
|
|
96
|
+
(0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
if (options.bundler !== 'none') {
|
|
100
|
+
addBundlerDependencies(tree, options);
|
|
101
|
+
}
|
|
102
|
+
if (!options.skipFormat) {
|
|
103
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
104
|
+
}
|
|
105
|
+
if (options.publishable) {
|
|
106
|
+
tasks.push(() => {
|
|
107
|
+
logNxReleaseDocsInfo();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
tasks.push(() => {
|
|
111
|
+
(0, log_show_project_command_1.logShowProjectCommand)(options.name);
|
|
112
|
+
});
|
|
113
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
114
|
+
}
|
|
115
|
+
exports.libraryGeneratorInternal = libraryGeneratorInternal;
|
|
116
|
+
async function addProject(tree, options) {
|
|
117
|
+
const projectConfiguration = {
|
|
118
|
+
root: options.projectRoot,
|
|
119
|
+
sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
|
|
120
|
+
projectType: 'library',
|
|
121
|
+
targets: {},
|
|
122
|
+
tags: options.parsedTags,
|
|
123
|
+
};
|
|
124
|
+
if (options.bundler &&
|
|
125
|
+
options.bundler !== 'none' &&
|
|
126
|
+
options.config !== 'npm-scripts') {
|
|
127
|
+
const outputPath = getOutputPath(options);
|
|
128
|
+
const executor = getBuildExecutor(options.bundler);
|
|
129
|
+
(0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, executor);
|
|
130
|
+
projectConfiguration.targets.build = {
|
|
131
|
+
executor,
|
|
132
|
+
outputs: ['{options.outputPath}'],
|
|
133
|
+
options: {
|
|
134
|
+
outputPath,
|
|
135
|
+
main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
|
|
136
|
+
tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
|
|
137
|
+
assets: [],
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
if (options.bundler === 'esbuild') {
|
|
141
|
+
projectConfiguration.targets.build.options.generatePackageJson = true;
|
|
142
|
+
projectConfiguration.targets.build.options.format = ['cjs'];
|
|
143
|
+
}
|
|
144
|
+
if (options.bundler === 'rollup') {
|
|
145
|
+
projectConfiguration.targets.build.options.project = `${options.projectRoot}/package.json`;
|
|
146
|
+
projectConfiguration.targets.build.options.compiler = 'swc';
|
|
147
|
+
projectConfiguration.targets.build.options.format = ['cjs', 'esm'];
|
|
148
|
+
}
|
|
149
|
+
if (options.bundler === 'swc' && options.skipTypeCheck) {
|
|
150
|
+
projectConfiguration.targets.build.options.skipTypeCheck = true;
|
|
151
|
+
}
|
|
152
|
+
if (!options.minimal &&
|
|
153
|
+
// TODO(jack): assets for rollup have validation that we need to fix (assets must be under <project-root>/src)
|
|
154
|
+
options.bundler !== 'rollup') {
|
|
155
|
+
projectConfiguration.targets.build.options.assets ??= [];
|
|
156
|
+
projectConfiguration.targets.build.options.assets.push((0, devkit_1.joinPathFragments)(options.projectRoot, '*.md'));
|
|
157
|
+
}
|
|
158
|
+
if (options.publishable) {
|
|
159
|
+
const packageRoot = (0, path_1.join)(defaultOutputDirectory, '{projectRoot}');
|
|
160
|
+
projectConfiguration.targets ??= {};
|
|
161
|
+
projectConfiguration.targets['nx-release-publish'] = {
|
|
162
|
+
options: {
|
|
163
|
+
packageRoot,
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
projectConfiguration.release = {
|
|
167
|
+
version: {
|
|
168
|
+
generatorOptions: {
|
|
169
|
+
packageRoot,
|
|
170
|
+
// using git tags to determine the current version is required here because
|
|
171
|
+
// the version in the package root is overridden with every build
|
|
172
|
+
currentVersionResolver: 'git-tag',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
await addProjectToNxReleaseConfig(tree, options, projectConfiguration);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (options.config === 'workspace' || options.config === 'project') {
|
|
180
|
+
(0, devkit_1.addProjectConfiguration)(tree, options.name, projectConfiguration);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
(0, devkit_1.addProjectConfiguration)(tree, options.name, {
|
|
184
|
+
root: projectConfiguration.root,
|
|
185
|
+
tags: projectConfiguration.tags,
|
|
186
|
+
targets: {},
|
|
187
|
+
}, true);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async function addLint(tree, options) {
|
|
191
|
+
const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
|
|
192
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.name);
|
|
193
|
+
const task = await lintProjectGenerator(tree, {
|
|
194
|
+
project: options.name,
|
|
195
|
+
linter: options.linter,
|
|
196
|
+
skipFormat: true,
|
|
197
|
+
tsConfigPaths: [
|
|
198
|
+
(0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
|
|
199
|
+
],
|
|
200
|
+
unitTestRunner: options.unitTestRunner,
|
|
201
|
+
setParserOptionsProject: options.setParserOptionsProject,
|
|
202
|
+
rootProject: options.rootProject,
|
|
203
|
+
addPlugin: options.addPlugin,
|
|
204
|
+
});
|
|
205
|
+
const { addOverrideToLintConfig, lintConfigHasOverride, isEslintConfigSupported, updateOverrideInLintConfig,
|
|
206
|
+
// nx-ignore-next-line
|
|
207
|
+
} = require('@nx/eslint/src/generators/utils/eslint-file');
|
|
208
|
+
// if config is not supported, we don't need to do anything
|
|
209
|
+
if (!isEslintConfigSupported(tree)) {
|
|
210
|
+
return task;
|
|
211
|
+
}
|
|
212
|
+
// Also update the root ESLint config. The lintProjectGenerator will not generate it for root projects.
|
|
213
|
+
// But we need to set the package.json checks.
|
|
214
|
+
if (options.rootProject) {
|
|
215
|
+
addOverrideToLintConfig(tree, '', {
|
|
216
|
+
files: ['*.json'],
|
|
217
|
+
parser: 'jsonc-eslint-parser',
|
|
218
|
+
rules: {
|
|
219
|
+
'@nx/dependency-checks': 'error',
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// If project lints package.json with @nx/dependency-checks, then add ignore files for
|
|
224
|
+
// build configuration files such as vite.config.ts. These config files need to be
|
|
225
|
+
// ignored, otherwise we will errors on missing dependencies that are for dev only.
|
|
226
|
+
if (lintConfigHasOverride(tree, projectConfiguration.root, (o) => Array.isArray(o.files)
|
|
227
|
+
? o.files.some((f) => f.match(/\.json$/))
|
|
228
|
+
: !!o.files?.match(/\.json$/), true)) {
|
|
229
|
+
updateOverrideInLintConfig(tree, projectConfiguration.root, (o) => o.rules?.['@nx/dependency-checks'], (o) => {
|
|
230
|
+
const value = o.rules['@nx/dependency-checks'];
|
|
231
|
+
let ruleSeverity;
|
|
232
|
+
let ruleOptions;
|
|
233
|
+
if (Array.isArray(value)) {
|
|
234
|
+
ruleSeverity = value[0];
|
|
235
|
+
ruleOptions = value[1];
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
ruleSeverity = value;
|
|
239
|
+
ruleOptions = {};
|
|
240
|
+
}
|
|
241
|
+
if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
|
|
242
|
+
ruleOptions.ignoredFiles = [
|
|
243
|
+
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
|
|
244
|
+
];
|
|
245
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
246
|
+
}
|
|
247
|
+
else if (options.bundler === 'rollup') {
|
|
248
|
+
ruleOptions.ignoredFiles = [
|
|
249
|
+
'{projectRoot}/rollup.config.{js,ts,mjs,mts}',
|
|
250
|
+
];
|
|
251
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
252
|
+
}
|
|
253
|
+
else if (options.bundler === 'esbuild') {
|
|
254
|
+
ruleOptions.ignoredFiles = [
|
|
255
|
+
'{projectRoot}/esbuild.config.{js,ts,mjs,mts}',
|
|
256
|
+
];
|
|
257
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
258
|
+
}
|
|
259
|
+
return o;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return task;
|
|
263
|
+
}
|
|
264
|
+
exports.addLint = addLint;
|
|
265
|
+
function addBundlerDependencies(tree, options) {
|
|
266
|
+
(0, devkit_1.updateJson)(tree, `${options.projectRoot}/package.json`, (json) => {
|
|
267
|
+
if (options.bundler === 'tsc') {
|
|
268
|
+
json.dependencies = {
|
|
269
|
+
...json.dependencies,
|
|
270
|
+
tslib: versions_1.tsLibVersion,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
else if (options.bundler === 'swc') {
|
|
274
|
+
json.dependencies = {
|
|
275
|
+
...json.dependencies,
|
|
276
|
+
'@swc/helpers': versions_1.swcHelpersVersion,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
return json;
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function updateTsConfig(tree, options) {
|
|
283
|
+
(0, devkit_1.updateJson)(tree, (0, path_1.join)(options.projectRoot, 'tsconfig.json'), (json) => {
|
|
284
|
+
if (options.strict) {
|
|
285
|
+
json.compilerOptions = {
|
|
286
|
+
...json.compilerOptions,
|
|
287
|
+
forceConsistentCasingInFileNames: true,
|
|
288
|
+
strict: true,
|
|
289
|
+
noImplicitOverride: true,
|
|
290
|
+
noPropertyAccessFromIndexSignature: true,
|
|
291
|
+
noImplicitReturns: true,
|
|
292
|
+
noFallthroughCasesInSwitch: true,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
return json;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
function addBabelRc(tree, options) {
|
|
299
|
+
const filename = '.babelrc';
|
|
300
|
+
const babelrc = {
|
|
301
|
+
presets: [['@nx/js/babel', { useBuiltIns: 'usage' }]],
|
|
302
|
+
};
|
|
303
|
+
(0, devkit_1.writeJson)(tree, (0, path_1.join)(options.projectRoot, filename), babelrc);
|
|
304
|
+
}
|
|
305
|
+
function createFiles(tree, options) {
|
|
306
|
+
const { className, name, propertyName } = (0, devkit_1.names)(options.projectNames.projectFileName);
|
|
307
|
+
createProjectTsConfigJson(tree, options);
|
|
308
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/lib'), options.projectRoot, {
|
|
309
|
+
...options,
|
|
310
|
+
dot: '.',
|
|
311
|
+
className,
|
|
312
|
+
name,
|
|
313
|
+
propertyName,
|
|
314
|
+
js: !!options.js,
|
|
315
|
+
cliCommand: 'nx',
|
|
316
|
+
strict: undefined,
|
|
317
|
+
tmpl: '',
|
|
318
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
|
|
319
|
+
buildable: options.bundler && options.bundler !== 'none',
|
|
320
|
+
hasUnitTestRunner: options.unitTestRunner !== 'none',
|
|
321
|
+
});
|
|
322
|
+
if (!options.rootProject) {
|
|
323
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/readme'), options.projectRoot, {
|
|
324
|
+
...options,
|
|
325
|
+
dot: '.',
|
|
326
|
+
className,
|
|
327
|
+
name,
|
|
328
|
+
propertyName,
|
|
329
|
+
js: !!options.js,
|
|
330
|
+
cliCommand: 'nx',
|
|
331
|
+
strict: undefined,
|
|
332
|
+
tmpl: '',
|
|
333
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
|
|
334
|
+
buildable: options.bundler && options.bundler !== 'none',
|
|
335
|
+
hasUnitTestRunner: options.unitTestRunner !== 'none',
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
339
|
+
(0, add_swc_dependencies_1.addSwcDependencies)(tree);
|
|
340
|
+
(0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' ? 'commonjs' : 'es6');
|
|
341
|
+
}
|
|
342
|
+
else if (options.includeBabelRc) {
|
|
343
|
+
addBabelRc(tree, options);
|
|
344
|
+
}
|
|
345
|
+
if (options.unitTestRunner === 'none') {
|
|
346
|
+
tree.delete((0, path_1.join)(options.projectRoot, 'src/lib', `${options.fileName}.spec.ts`));
|
|
347
|
+
tree.delete((0, path_1.join)(options.projectRoot, 'src/app', `${options.fileName}.spec.ts`));
|
|
348
|
+
}
|
|
349
|
+
if (options.js) {
|
|
350
|
+
(0, devkit_1.toJS)(tree);
|
|
351
|
+
}
|
|
352
|
+
const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
|
|
353
|
+
if (tree.exists(packageJsonPath)) {
|
|
354
|
+
(0, devkit_1.updateJson)(tree, packageJsonPath, (json) => {
|
|
355
|
+
json.name = options.importPath;
|
|
356
|
+
json.version = '0.0.1';
|
|
357
|
+
// If the package is publishable or root/standalone, we should remove the private field.
|
|
358
|
+
if (json.private && (options.publishable || options.rootProject)) {
|
|
359
|
+
delete json.private;
|
|
360
|
+
}
|
|
361
|
+
if (!options.publishable && !options.rootProject) {
|
|
362
|
+
json.private = true;
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
...json,
|
|
366
|
+
dependencies: {
|
|
367
|
+
...json.dependencies,
|
|
368
|
+
...determineDependencies(options),
|
|
369
|
+
},
|
|
370
|
+
...determineEntryFields(options),
|
|
371
|
+
};
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
const packageJson = {
|
|
376
|
+
name: options.importPath,
|
|
377
|
+
version: '0.0.1',
|
|
378
|
+
dependencies: determineDependencies(options),
|
|
379
|
+
...determineEntryFields(options),
|
|
380
|
+
};
|
|
381
|
+
if (!options.publishable && !options.rootProject) {
|
|
382
|
+
packageJson.private = true;
|
|
383
|
+
}
|
|
384
|
+
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
385
|
+
}
|
|
386
|
+
if (options.config === 'npm-scripts') {
|
|
387
|
+
(0, devkit_1.updateJson)(tree, packageJsonPath, (json) => {
|
|
388
|
+
json.scripts = {
|
|
389
|
+
build: "echo 'implement build'",
|
|
390
|
+
test: "echo 'implement test'",
|
|
391
|
+
};
|
|
392
|
+
return json;
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
else if ((!options.bundler || options.bundler === 'none') &&
|
|
396
|
+
!(options.projectRoot === '.')) {
|
|
397
|
+
tree.delete(packageJsonPath);
|
|
398
|
+
}
|
|
399
|
+
if (options.minimal && !(options.projectRoot === '.')) {
|
|
400
|
+
tree.delete((0, path_1.join)(options.projectRoot, 'README.md'));
|
|
401
|
+
}
|
|
402
|
+
updateTsConfig(tree, options);
|
|
403
|
+
}
|
|
404
|
+
async function addJest(tree, options) {
|
|
405
|
+
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
|
|
406
|
+
return await configurationGenerator(tree, {
|
|
407
|
+
...options,
|
|
408
|
+
project: options.name,
|
|
409
|
+
setupFile: 'none',
|
|
410
|
+
supportTsx: false,
|
|
411
|
+
skipSerializers: true,
|
|
412
|
+
testEnvironment: options.testEnvironment,
|
|
413
|
+
skipFormat: true,
|
|
414
|
+
compiler: options.bundler === 'swc' || options.bundler === 'tsc'
|
|
415
|
+
? options.bundler
|
|
416
|
+
: options.bundler === 'rollup'
|
|
417
|
+
? 'swc'
|
|
418
|
+
: undefined,
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
function replaceJestConfig(tree, options) {
|
|
422
|
+
const filesDir = (0, path_1.join)(__dirname, './files/jest-config');
|
|
423
|
+
// the existing config has to be deleted otherwise the new config won't overwrite it
|
|
424
|
+
const existingJestConfig = (0, devkit_1.joinPathFragments)(filesDir, `jest.config.${options.js ? 'js' : 'ts'}`);
|
|
425
|
+
if (tree.exists(existingJestConfig)) {
|
|
426
|
+
tree.delete(existingJestConfig);
|
|
427
|
+
}
|
|
428
|
+
// replace with JS:SWC specific jest config
|
|
429
|
+
(0, devkit_1.generateFiles)(tree, filesDir, options.projectRoot, {
|
|
430
|
+
ext: options.js ? 'js' : 'ts',
|
|
431
|
+
js: !!options.js,
|
|
432
|
+
project: options.name,
|
|
433
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
|
|
434
|
+
projectRoot: options.projectRoot,
|
|
435
|
+
testEnvironment: options.testEnvironment,
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
async function normalizeOptions(tree, options) {
|
|
439
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
440
|
+
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
441
|
+
nxJson.useInferencePlugins !== false;
|
|
442
|
+
options.addPlugin ??= addPlugin;
|
|
443
|
+
/**
|
|
444
|
+
* We are deprecating the compiler and the buildable options.
|
|
445
|
+
* However, we want to keep the existing behavior for now.
|
|
446
|
+
*
|
|
447
|
+
* So, if the user has not provided a bundler, we will use the compiler option, if any.
|
|
448
|
+
*
|
|
449
|
+
* If the user has not provided a bundler and no compiler, but has set buildable to true,
|
|
450
|
+
* we will use tsc, since that is the compiler the old generator used to default to, if buildable was true
|
|
451
|
+
* and no compiler was provided.
|
|
452
|
+
*
|
|
453
|
+
* If the user has not provided a bundler and no compiler, and has not set buildable to true, then
|
|
454
|
+
* set the bundler to tsc, to preserve old default behaviour (buildable: true by default).
|
|
455
|
+
*
|
|
456
|
+
* If it's publishable, we need to build the code before publishing it, so again
|
|
457
|
+
* we default to `tsc`. In the previous version of this, it would set `buildable` to true
|
|
458
|
+
* and that would default to `tsc`.
|
|
459
|
+
*
|
|
460
|
+
* In the past, the only way to get a non-buildable library was to set buildable to false.
|
|
461
|
+
* Now, the only way to get a non-buildble library is to set bundler to none.
|
|
462
|
+
* By default, with nothing provided, libraries are buildable with `@nx/js:tsc`.
|
|
463
|
+
*/
|
|
464
|
+
options.bundler = options.bundler ?? options.compiler ?? 'tsc';
|
|
465
|
+
// ensure programmatic runs have an expected default
|
|
466
|
+
if (!options.config) {
|
|
467
|
+
options.config = 'project';
|
|
468
|
+
}
|
|
469
|
+
if (options.publishable) {
|
|
470
|
+
if (!options.importPath) {
|
|
471
|
+
throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
|
|
472
|
+
}
|
|
473
|
+
if (options.bundler === 'none') {
|
|
474
|
+
options.bundler = 'tsc';
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
// This is to preserve old behavior, buildable: false
|
|
478
|
+
if (options.publishable === false && options.buildable === false) {
|
|
479
|
+
options.bundler = 'none';
|
|
480
|
+
}
|
|
481
|
+
const { Linter } = (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
|
|
482
|
+
if (options.config === 'npm-scripts') {
|
|
483
|
+
options.unitTestRunner = 'none';
|
|
484
|
+
options.linter = Linter.None;
|
|
485
|
+
options.bundler = 'none';
|
|
486
|
+
}
|
|
487
|
+
if ((options.bundler === 'swc' || options.bundler === 'rollup') &&
|
|
488
|
+
options.skipTypeCheck == null) {
|
|
489
|
+
options.skipTypeCheck = false;
|
|
490
|
+
}
|
|
491
|
+
if (!options.unitTestRunner && options.bundler === 'vite') {
|
|
492
|
+
options.unitTestRunner = 'vitest';
|
|
493
|
+
}
|
|
494
|
+
else if (!options.unitTestRunner && options.config !== 'npm-scripts') {
|
|
495
|
+
options.unitTestRunner = 'jest';
|
|
496
|
+
}
|
|
497
|
+
if (!options.linter && options.config !== 'npm-scripts') {
|
|
498
|
+
options.linter = Linter.EsLint;
|
|
499
|
+
}
|
|
500
|
+
const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
|
|
501
|
+
name: options.name,
|
|
502
|
+
projectType: 'library',
|
|
503
|
+
directory: options.directory,
|
|
504
|
+
importPath: options.importPath,
|
|
505
|
+
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
506
|
+
rootProject: options.rootProject,
|
|
507
|
+
callingGenerator: '@nx/js:library',
|
|
508
|
+
});
|
|
509
|
+
options.rootProject = projectRoot === '.';
|
|
510
|
+
const fileName = getCaseAwareFileName({
|
|
511
|
+
fileName: options.simpleName
|
|
512
|
+
? projectNames.projectSimpleName
|
|
513
|
+
: projectNames.projectFileName,
|
|
514
|
+
pascalCaseFiles: options.pascalCaseFiles,
|
|
515
|
+
});
|
|
516
|
+
const parsedTags = options.tags
|
|
517
|
+
? options.tags.split(',').map((s) => s.trim())
|
|
518
|
+
: [];
|
|
519
|
+
options.minimal ??= false;
|
|
520
|
+
return {
|
|
521
|
+
...options,
|
|
522
|
+
fileName,
|
|
523
|
+
name: projectName,
|
|
524
|
+
projectNames,
|
|
525
|
+
projectRoot,
|
|
526
|
+
parsedTags,
|
|
527
|
+
importPath,
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function getCaseAwareFileName(options) {
|
|
531
|
+
const normalized = (0, devkit_1.names)(options.fileName);
|
|
532
|
+
return options.pascalCaseFiles ? normalized.className : normalized.fileName;
|
|
533
|
+
}
|
|
534
|
+
function addProjectDependencies(tree, options) {
|
|
535
|
+
if (options.bundler == 'esbuild') {
|
|
536
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
537
|
+
'@nx/esbuild': versions_1.nxVersion,
|
|
538
|
+
'@types/node': versions_1.typesNodeVersion,
|
|
539
|
+
esbuild: versions_1.esbuildVersion,
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
else if (options.bundler == 'rollup') {
|
|
543
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/rollup': versions_1.nxVersion, '@types/node': versions_1.typesNodeVersion });
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@types/node': versions_1.typesNodeVersion });
|
|
547
|
+
}
|
|
548
|
+
// Vite is being installed in the next step if bundler is vite
|
|
549
|
+
// noop
|
|
550
|
+
return () => { };
|
|
551
|
+
}
|
|
552
|
+
function getBuildExecutor(bundler) {
|
|
553
|
+
switch (bundler) {
|
|
554
|
+
case 'esbuild':
|
|
555
|
+
return `@nx/esbuild:esbuild`;
|
|
556
|
+
case 'rollup':
|
|
557
|
+
return `@nx/rollup:rollup`;
|
|
558
|
+
case 'swc':
|
|
559
|
+
case 'tsc':
|
|
560
|
+
return `@nx/js:${bundler}`;
|
|
561
|
+
case 'vite':
|
|
562
|
+
return `@nx/vite:build`;
|
|
563
|
+
case 'none':
|
|
564
|
+
default:
|
|
565
|
+
return undefined;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
function getOutputPath(options) {
|
|
569
|
+
const parts = [defaultOutputDirectory];
|
|
570
|
+
if (options.projectRoot === '.') {
|
|
571
|
+
parts.push(options.name);
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
parts.push(options.projectRoot);
|
|
575
|
+
}
|
|
576
|
+
return (0, devkit_1.joinPathFragments)(...parts);
|
|
577
|
+
}
|
|
578
|
+
function createProjectTsConfigJson(tree, options) {
|
|
579
|
+
const tsconfig = {
|
|
580
|
+
extends: options.rootProject
|
|
581
|
+
? undefined
|
|
582
|
+
: (0, ts_config_1.getRelativePathToRootTsConfig)(tree, options.projectRoot),
|
|
583
|
+
compilerOptions: {
|
|
584
|
+
...(options.rootProject ? create_ts_config_1.tsConfigBaseOptions : {}),
|
|
585
|
+
module: 'commonjs',
|
|
586
|
+
allowJs: options.js ? true : undefined,
|
|
587
|
+
},
|
|
588
|
+
files: [],
|
|
589
|
+
include: [],
|
|
590
|
+
references: [
|
|
591
|
+
{
|
|
592
|
+
path: './tsconfig.lib.json',
|
|
593
|
+
},
|
|
594
|
+
],
|
|
595
|
+
};
|
|
596
|
+
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), tsconfig);
|
|
597
|
+
}
|
|
598
|
+
function determineDependencies(options) {
|
|
599
|
+
switch (options.bundler) {
|
|
600
|
+
case 'tsc':
|
|
601
|
+
// importHelpers is true by default, so need to add tslib as a dependency.
|
|
602
|
+
return {
|
|
603
|
+
tslib: versions_1.tsLibVersion,
|
|
604
|
+
};
|
|
605
|
+
case 'swc':
|
|
606
|
+
// externalHelpers is true by default, so need to add swc helpers as a dependency.
|
|
607
|
+
return {
|
|
608
|
+
'@swc/helpers': versions_1.swcHelpersVersion,
|
|
609
|
+
};
|
|
610
|
+
default: {
|
|
611
|
+
// In other cases (vite, rollup, esbuild), helpers are bundled so no need to add them as a dependency.
|
|
612
|
+
return {};
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
function determineEntryFields(options) {
|
|
617
|
+
switch (options.bundler) {
|
|
618
|
+
case 'tsc':
|
|
619
|
+
return {
|
|
620
|
+
type: 'commonjs',
|
|
621
|
+
main: './src/index.js',
|
|
622
|
+
typings: './src/index.d.ts',
|
|
623
|
+
};
|
|
624
|
+
case 'swc':
|
|
625
|
+
return {
|
|
626
|
+
type: 'commonjs',
|
|
627
|
+
main: './src/index.js',
|
|
628
|
+
typings: './src/index.d.ts',
|
|
629
|
+
};
|
|
630
|
+
case 'rollup':
|
|
631
|
+
return {
|
|
632
|
+
type: 'commonjs',
|
|
633
|
+
main: './index.cjs',
|
|
634
|
+
module: './index.js',
|
|
635
|
+
// typings is missing for rollup currently
|
|
636
|
+
};
|
|
637
|
+
case 'vite':
|
|
638
|
+
return {
|
|
639
|
+
// Since we're publishing both formats, skip the type field.
|
|
640
|
+
// Bundlers or Node will determine the entry point to use.
|
|
641
|
+
main: './index.js',
|
|
642
|
+
module: './index.mjs',
|
|
643
|
+
typings: './index.d.ts',
|
|
644
|
+
};
|
|
645
|
+
case 'esbuild':
|
|
646
|
+
// For libraries intended for Node, use CJS.
|
|
647
|
+
return {
|
|
648
|
+
type: 'commonjs',
|
|
649
|
+
main: './index.cjs',
|
|
650
|
+
// typings is missing for esbuild currently
|
|
651
|
+
};
|
|
652
|
+
default: {
|
|
653
|
+
return {
|
|
654
|
+
// CJS is the safest optional for now due to lack of support from some packages
|
|
655
|
+
// also setting `type: module` results in different resolution behavior (e.g. import 'foo' no longer resolves to 'foo/index.js')
|
|
656
|
+
type: 'commonjs',
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
function projectsConfigMatchesProject(projectsConfig, project) {
|
|
662
|
+
if (!projectsConfig) {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
if (typeof projectsConfig === 'string') {
|
|
666
|
+
projectsConfig = [projectsConfig];
|
|
667
|
+
}
|
|
668
|
+
const graph = {
|
|
669
|
+
[project.name]: project,
|
|
670
|
+
};
|
|
671
|
+
const matchingProjects = (0, find_matching_projects_1.findMatchingProjects)(projectsConfig, graph);
|
|
672
|
+
return matchingProjects.includes(project.name);
|
|
673
|
+
}
|
|
674
|
+
async function addProjectToNxReleaseConfig(tree, options, projectConfiguration) {
|
|
675
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
676
|
+
const addPreVersionCommand = () => {
|
|
677
|
+
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
678
|
+
nxJson.release = {
|
|
679
|
+
...nxJson.release,
|
|
680
|
+
version: {
|
|
681
|
+
preVersionCommand: `${pmc.dlx} nx run-many -t build`,
|
|
682
|
+
...nxJson.release?.version,
|
|
683
|
+
},
|
|
684
|
+
};
|
|
685
|
+
};
|
|
686
|
+
if (!nxJson.release || (!nxJson.release.projects && !nxJson.release.groups)) {
|
|
687
|
+
// skip adding any projects configuration since the new project should be
|
|
688
|
+
// automatically included by nx release's default project detection logic
|
|
689
|
+
addPreVersionCommand();
|
|
690
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const project = {
|
|
694
|
+
name: options.name,
|
|
695
|
+
type: 'lib',
|
|
696
|
+
data: {
|
|
697
|
+
root: projectConfiguration.root,
|
|
698
|
+
tags: projectConfiguration.tags,
|
|
699
|
+
},
|
|
700
|
+
};
|
|
701
|
+
if (projectsConfigMatchesProject(nxJson.release.projects, project)) {
|
|
702
|
+
devkit_1.output.log({
|
|
703
|
+
title: `Project already included in existing release configuration`,
|
|
704
|
+
});
|
|
705
|
+
addPreVersionCommand();
|
|
706
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
if (Array.isArray(nxJson.release.projects)) {
|
|
710
|
+
nxJson.release.projects.push(options.name);
|
|
711
|
+
addPreVersionCommand();
|
|
712
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
713
|
+
devkit_1.output.log({
|
|
714
|
+
title: `Added project to existing release configuration`,
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
if (nxJson.release.groups) {
|
|
718
|
+
const allGroups = Object.entries(nxJson.release.groups);
|
|
719
|
+
for (const [name, group] of allGroups) {
|
|
720
|
+
if (projectsConfigMatchesProject(group.projects, project)) {
|
|
721
|
+
addPreVersionCommand();
|
|
722
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
723
|
+
return `Project already included in existing release configuration for group ${name}`;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
devkit_1.output.warn({
|
|
727
|
+
title: `Could not find a release group that includes ${options.name}`,
|
|
728
|
+
bodyLines: [
|
|
729
|
+
`Ensure that ${options.name} is included in a release group's "projects" list in nx.json so it can be published with "nx release"`,
|
|
730
|
+
],
|
|
731
|
+
});
|
|
732
|
+
addPreVersionCommand();
|
|
733
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
if (typeof nxJson.release.projects === 'string') {
|
|
737
|
+
nxJson.release.projects = [nxJson.release.projects, options.name];
|
|
738
|
+
addPreVersionCommand();
|
|
739
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
740
|
+
devkit_1.output.log({
|
|
741
|
+
title: `Added project to existing release configuration`,
|
|
742
|
+
});
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function logNxReleaseDocsInfo() {
|
|
747
|
+
devkit_1.output.log({
|
|
748
|
+
title: `📦 To learn how to publish this library, see https://nx.dev/core-features/manage-releases.`,
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
exports.default = libraryGenerator;
|