@nx/js 16.7.0-beta.1 → 16.7.0-beta.4

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/generators.json CHANGED
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "generators": {
40
40
  "library": {
41
- "factory": "./src/generators/library/library#libraryGenerator",
41
+ "factory": "./src/generators/library/library#libraryGeneratorInternal",
42
42
  "schema": "./src/generators/library/schema.json",
43
43
  "aliases": ["lib"],
44
44
  "x-type": "library",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "16.7.0-beta.1",
3
+ "version": "16.7.0-beta.4",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -16,7 +16,7 @@
16
16
  "Tsc",
17
17
  "CLI"
18
18
  ],
19
- "main": "src/index.js",
19
+ "main": "./src/index.js",
20
20
  "typings": "src/index.d.ts",
21
21
  "license": "MIT",
22
22
  "bugs": {
@@ -39,9 +39,9 @@
39
39
  "@babel/preset-env": "^7.22.9",
40
40
  "@babel/preset-typescript": "^7.22.5",
41
41
  "@babel/runtime": "^7.22.6",
42
- "@nrwl/js": "16.7.0-beta.1",
43
- "@nx/devkit": "16.7.0-beta.1",
44
- "@nx/workspace": "16.7.0-beta.1",
42
+ "@nrwl/js": "16.7.0-beta.4",
43
+ "@nx/devkit": "16.7.0-beta.4",
44
+ "@nx/workspace": "16.7.0-beta.4",
45
45
  "@phenomnomnominal/tsquery": "~5.0.1",
46
46
  "babel-plugin-const-enum": "^1.0.1",
47
47
  "babel-plugin-macros": "^2.8.0",
@@ -70,6 +70,6 @@
70
70
  "publishConfig": {
71
71
  "access": "public"
72
72
  },
73
- "types": "./src/index.d.ts",
74
- "gitHead": "50a145bb64edcf76985184a9a83d1449dcd4f3d9"
73
+ "type": "commonjs",
74
+ "gitHead": "dcbba686b182737b66ebbfb9db372769e77ba005"
75
75
  }
@@ -1,15 +1,17 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { type ProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
3
  import { LibraryGeneratorSchema } from '../../utils/schema';
3
4
  export declare function libraryGenerator(tree: Tree, schema: LibraryGeneratorSchema): Promise<GeneratorCallback>;
4
- export declare function projectGenerator(tree: Tree, schema: LibraryGeneratorSchema, destinationDir: string, filesDir: string): Promise<GeneratorCallback>;
5
+ export declare function libraryGeneratorInternal(tree: Tree, schema: LibraryGeneratorSchema): Promise<GeneratorCallback>;
5
6
  export interface NormalizedSchema extends LibraryGeneratorSchema {
6
7
  name: string;
8
+ projectNames: ProjectNameAndRootOptions['names'];
7
9
  fileName: string;
8
10
  projectRoot: string;
9
- projectDirectory: string;
10
11
  parsedTags: string[];
11
12
  importPath?: string;
12
13
  }
13
- export declare function addLint(tree: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
14
+ export type AddLintOptions = Pick<NormalizedSchema, 'name' | 'linter' | 'projectRoot' | 'unitTestRunner' | 'js' | 'setParserOptionsProject' | 'rootProject'>;
15
+ export declare function addLint(tree: Tree, options: AddLintOptions): Promise<GeneratorCallback>;
14
16
  export default libraryGenerator;
15
17
  export declare const librarySchematic: (generatorOptions: LibraryGeneratorSchema) => (tree: any, context: any) => Promise<any>;
@@ -1,36 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.librarySchematic = exports.addLint = exports.projectGenerator = exports.libraryGenerator = void 0;
3
+ exports.librarySchematic = exports.addLint = exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
7
  const ts_config_1 = require("../../utils/typescript/ts-config");
7
8
  const path_1 = require("path");
8
9
  const minimal_publish_script_1 = require("../../utils/minimal-publish-script");
9
10
  const add_swc_config_1 = require("../../utils/swc/add-swc-config");
10
11
  const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
11
- const get_import_path_1 = require("../../utils/get-import-path");
12
12
  const versions_1 = require("../../utils/versions");
13
13
  const init_1 = require("../init/init");
14
14
  const generator_1 = require("../setup-verdaccio/generator");
15
15
  const create_ts_config_1 = require("../../utils/typescript/create-ts-config");
16
16
  function libraryGenerator(tree, schema) {
17
17
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
18
- const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(schema.directory);
19
- schema.directory = projectDirectory;
20
- const libsDir = schema.rootProject
21
- ? '.'
22
- : layoutDirectory !== null && layoutDirectory !== void 0 ? layoutDirectory : (0, devkit_1.getWorkspaceLayout)(tree).libsDir;
23
- return projectGenerator(tree, schema, libsDir, (0, path_1.join)(__dirname, './files'));
18
+ return yield libraryGeneratorInternal(tree, Object.assign({
19
+ // provide a default projectNameAndRootFormat to avoid breaking changes
20
+ // to external generators invoking this one
21
+ projectNameAndRootFormat: 'derived' }, schema));
24
22
  });
25
23
  }
26
24
  exports.libraryGenerator = libraryGenerator;
27
- function projectGenerator(tree, schema, destinationDir, filesDir) {
25
+ function libraryGeneratorInternal(tree, schema) {
28
26
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
27
+ const filesDir = (0, path_1.join)(__dirname, './files');
29
28
  const tasks = [];
30
29
  tasks.push(yield (0, init_1.default)(tree, Object.assign(Object.assign({}, schema), { skipFormat: true, tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json' })));
31
- const options = normalizeOptions(tree, schema, destinationDir);
30
+ const options = yield normalizeOptions(tree, schema);
32
31
  createFiles(tree, options, `${filesDir}/lib`);
33
- addProject(tree, options, destinationDir);
32
+ addProject(tree, options);
34
33
  tasks.push(addProjectDependencies(tree, options));
35
34
  if (options.publishable) {
36
35
  tasks.push(yield (0, generator_1.default)(tree, Object.assign(Object.assign({}, options), { skipFormat: true })));
@@ -86,8 +85,8 @@ function projectGenerator(tree, schema, destinationDir, filesDir) {
86
85
  return (0, devkit_1.runTasksInSerial)(...tasks);
87
86
  });
88
87
  }
89
- exports.projectGenerator = projectGenerator;
90
- function addProject(tree, options, destinationDir) {
88
+ exports.libraryGeneratorInternal = libraryGeneratorInternal;
89
+ function addProject(tree, options) {
91
90
  var _a;
92
91
  var _b;
93
92
  const projectConfiguration = {
@@ -100,7 +99,7 @@ function addProject(tree, options, destinationDir) {
100
99
  if (options.bundler &&
101
100
  options.bundler !== 'none' &&
102
101
  options.config !== 'npm-scripts') {
103
- const outputPath = getOutputPath(options, destinationDir);
102
+ const outputPath = getOutputPath(options);
104
103
  projectConfiguration.targets.build = {
105
104
  executor: getBuildExecutor(options.bundler),
106
105
  outputs: ['{options.outputPath}'],
@@ -212,7 +211,7 @@ function addBabelRc(tree, options) {
212
211
  (0, devkit_1.writeJson)(tree, (0, path_1.join)(options.projectRoot, filename), babelrc);
213
212
  }
214
213
  function createFiles(tree, options, filesDir) {
215
- const { className, name, propertyName } = (0, devkit_1.names)(options.name);
214
+ const { className, name, propertyName } = (0, devkit_1.names)(options.projectNames.projectFileName);
216
215
  createProjectTsConfigJson(tree, options);
217
216
  (0, devkit_1.generateFiles)(tree, filesDir, options.projectRoot, Object.assign(Object.assign({}, options), { dot: '.', className,
218
217
  name,
@@ -290,90 +289,88 @@ function replaceJestConfig(tree, options, filesDir) {
290
289
  testEnvironment: options.testEnvironment,
291
290
  });
292
291
  }
293
- function normalizeOptions(tree, options, destinationDir) {
294
- /**
295
- * We are deprecating the compiler and the buildable options.
296
- * However, we want to keep the existing behavior for now.
297
- *
298
- * So, if the user has not provided a bundler, we will use the compiler option, if any.
299
- *
300
- * If the user has not provided a bundler and no compiler, but has set buildable to true,
301
- * we will use tsc, since that is the compiler the old generator used to default to, if buildable was true
302
- * and no compiler was provided.
303
- *
304
- * If the user has not provided a bundler and no compiler, and has not set buildable to true, then
305
- * set the bundler to tsc, to preserve old default behaviour (buildable: true by default).
306
- *
307
- * If it's publishable, we need to build the code before publishing it, so again
308
- * we default to `tsc`. In the previous version of this, it would set `buildable` to true
309
- * and that would default to `tsc`.
310
- *
311
- * In the past, the only way to get a non-buildable library was to set buildable to false.
312
- * Now, the only way to get a non-buildble library is to set bundler to none.
313
- * By default, with nothing provided, libraries are buildable with `@nx/js:tsc`.
314
- */
315
- var _a, _b, _c, _d;
316
- options.bundler = (_b = (_a = options.bundler) !== null && _a !== void 0 ? _a : options.compiler) !== null && _b !== void 0 ? _b : 'tsc';
317
- // ensure programmatic runs have an expected default
318
- if (!options.config) {
319
- options.config = 'project';
320
- }
321
- if (options.publishable) {
322
- if (!options.importPath) {
323
- 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)`);
292
+ function normalizeOptions(tree, options) {
293
+ var _a, _b, _c;
294
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
295
+ /**
296
+ * We are deprecating the compiler and the buildable options.
297
+ * However, we want to keep the existing behavior for now.
298
+ *
299
+ * So, if the user has not provided a bundler, we will use the compiler option, if any.
300
+ *
301
+ * If the user has not provided a bundler and no compiler, but has set buildable to true,
302
+ * we will use tsc, since that is the compiler the old generator used to default to, if buildable was true
303
+ * and no compiler was provided.
304
+ *
305
+ * If the user has not provided a bundler and no compiler, and has not set buildable to true, then
306
+ * set the bundler to tsc, to preserve old default behaviour (buildable: true by default).
307
+ *
308
+ * If it's publishable, we need to build the code before publishing it, so again
309
+ * we default to `tsc`. In the previous version of this, it would set `buildable` to true
310
+ * and that would default to `tsc`.
311
+ *
312
+ * In the past, the only way to get a non-buildable library was to set buildable to false.
313
+ * Now, the only way to get a non-buildble library is to set bundler to none.
314
+ * By default, with nothing provided, libraries are buildable with `@nx/js:tsc`.
315
+ */
316
+ options.bundler = (_b = (_a = options.bundler) !== null && _a !== void 0 ? _a : options.compiler) !== null && _b !== void 0 ? _b : 'tsc';
317
+ // ensure programmatic runs have an expected default
318
+ if (!options.config) {
319
+ options.config = 'project';
324
320
  }
325
- if (options.bundler === 'none') {
326
- options.bundler = 'tsc';
321
+ if (options.publishable) {
322
+ if (!options.importPath) {
323
+ 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)`);
324
+ }
325
+ if (options.bundler === 'none') {
326
+ options.bundler = 'tsc';
327
+ }
327
328
  }
328
- }
329
- // This is to preserve old behaviour, buildable: false
330
- if (options.publishable === false && options.buildable === false) {
331
- options.bundler = 'none';
332
- }
333
- const { Linter } = (0, devkit_1.ensurePackage)('@nx/linter', versions_1.nxVersion);
334
- if (options.config === 'npm-scripts') {
335
- options.unitTestRunner = 'none';
336
- options.linter = Linter.None;
337
- options.bundler = 'none';
338
- }
339
- if ((options.bundler === 'swc' || options.bundler === 'rollup') &&
340
- options.skipTypeCheck == null) {
341
- options.skipTypeCheck = false;
342
- }
343
- const name = (0, devkit_1.names)(options.name).fileName;
344
- const projectDirectory = options.directory
345
- ? `${(0, devkit_1.names)(options.directory).fileName}/${name}`
346
- : options.rootProject
347
- ? '.'
348
- : name;
349
- if (!options.unitTestRunner && options.bundler === 'vite') {
350
- options.unitTestRunner = 'vitest';
351
- }
352
- else if (!options.unitTestRunner && options.config !== 'npm-scripts') {
353
- options.unitTestRunner = 'jest';
354
- }
355
- if (!options.linter && options.config !== 'npm-scripts') {
356
- options.linter = Linter.EsLint;
357
- }
358
- const projectName = options.rootProject
359
- ? name
360
- : projectDirectory.replace(new RegExp('/', 'g'), '-');
361
- const fileName = getCaseAwareFileName({
362
- fileName: options.simpleName ? name : projectName,
363
- pascalCaseFiles: options.pascalCaseFiles,
329
+ // This is to preserve old behaviour, buildable: false
330
+ if (options.publishable === false && options.buildable === false) {
331
+ options.bundler = 'none';
332
+ }
333
+ const { Linter } = (0, devkit_1.ensurePackage)('@nx/linter', versions_1.nxVersion);
334
+ if (options.config === 'npm-scripts') {
335
+ options.unitTestRunner = 'none';
336
+ options.linter = Linter.None;
337
+ options.bundler = 'none';
338
+ }
339
+ if ((options.bundler === 'swc' || options.bundler === 'rollup') &&
340
+ options.skipTypeCheck == null) {
341
+ options.skipTypeCheck = false;
342
+ }
343
+ if (!options.unitTestRunner && options.bundler === 'vite') {
344
+ options.unitTestRunner = 'vitest';
345
+ }
346
+ else if (!options.unitTestRunner && options.config !== 'npm-scripts') {
347
+ options.unitTestRunner = 'jest';
348
+ }
349
+ if (!options.linter && options.config !== 'npm-scripts') {
350
+ options.linter = Linter.EsLint;
351
+ }
352
+ const { projectName, names: projectNames, projectDirectory, importPath, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
353
+ name: options.name,
354
+ projectType: 'library',
355
+ directory: options.directory,
356
+ importPath: options.importPath,
357
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
358
+ rootProject: options.rootProject,
359
+ });
360
+ options.rootProject = projectDirectory === '.';
361
+ const fileName = getCaseAwareFileName({
362
+ fileName: options.simpleName
363
+ ? projectNames.projectSimpleName
364
+ : projectNames.projectFileName,
365
+ pascalCaseFiles: options.pascalCaseFiles,
366
+ });
367
+ const parsedTags = options.tags
368
+ ? options.tags.split(',').map((s) => s.trim())
369
+ : [];
370
+ (_c = options.minimal) !== null && _c !== void 0 ? _c : (options.minimal = false);
371
+ return Object.assign(Object.assign({}, options), { fileName, name: projectName, projectNames, projectRoot: projectDirectory, parsedTags,
372
+ importPath });
364
373
  });
365
- const projectRoot = (0, devkit_1.joinPathFragments)(destinationDir, projectDirectory);
366
- const parsedTags = options.tags
367
- ? options.tags.split(',').map((s) => s.trim())
368
- : [];
369
- const importPath = options.rootProject
370
- ? (_c = (0, devkit_1.readJson)(tree, 'package.json').name) !== null && _c !== void 0 ? _c : (0, get_import_path_1.getImportPath)(tree, 'core')
371
- : options.importPath || (0, get_import_path_1.getImportPath)(tree, projectDirectory);
372
- (_d = options.minimal) !== null && _d !== void 0 ? _d : (options.minimal = false);
373
- return Object.assign(Object.assign({}, options), { fileName, name: projectName, projectRoot,
374
- projectDirectory,
375
- parsedTags,
376
- importPath });
377
374
  }
378
375
  function getCaseAwareFileName(options) {
379
376
  const normalized = (0, devkit_1.names)(options.fileName);
@@ -413,16 +410,13 @@ function getBuildExecutor(bundler) {
413
410
  return undefined;
414
411
  }
415
412
  }
416
- function getOutputPath(options, destinationDir) {
413
+ function getOutputPath(options) {
417
414
  const parts = ['dist'];
418
- if (destinationDir) {
419
- parts.push(destinationDir);
420
- }
421
- if (options.projectDirectory === '.') {
415
+ if (options.projectRoot === '.') {
422
416
  parts.push(options.name);
423
417
  }
424
418
  else {
425
- parts.push(options.projectDirectory);
419
+ parts.push(options.projectRoot);
426
420
  }
427
421
  return (0, devkit_1.joinPathFragments)(...parts);
428
422
  }
@@ -506,4 +500,4 @@ function determineEntryFields(options) {
506
500
  }
507
501
  }
508
502
  exports.default = libraryGenerator;
509
- exports.librarySchematic = (0, devkit_1.convertNxGenerator)(libraryGenerator);
503
+ exports.librarySchematic = (0, devkit_1.convertNxGenerator)(libraryGeneratorInternal);
@@ -14,13 +14,18 @@
14
14
  "index": 0
15
15
  },
16
16
  "x-prompt": "What name would you like to use for the library?",
17
- "pattern": "^[a-zA-Z].*$"
17
+ "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$"
18
18
  },
19
19
  "directory": {
20
20
  "type": "string",
21
21
  "description": "A directory where the lib is placed.",
22
22
  "x-priority": "important"
23
23
  },
24
+ "projectNameAndRootFormat": {
25
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
26
+ "type": "string",
27
+ "enum": ["as-provided", "derived"]
28
+ },
24
29
  "linter": {
25
30
  "description": "The tool to use for running lint checks.",
26
31
  "type": "string",
@@ -1,3 +1,4 @@
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-directory-utils';
1
2
  // nx-ignore-next-line
2
3
  const { Linter } = require('@nx/linter'); // use require to import to avoid circular dependency
3
4
  import type { AssetGlob, FileInputOutput } from './assets/assets';
@@ -9,6 +10,7 @@ export type Bundler = 'swc' | 'tsc' | 'rollup' | 'vite' | 'esbuild' | 'none';
9
10
  export interface LibraryGeneratorSchema {
10
11
  name: string;
11
12
  directory?: string;
13
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
12
14
  skipFormat?: boolean;
13
15
  tags?: string;
14
16
  skipTsConfig?: boolean;