@nx/js 16.4.0-beta.8 → 16.4.0-beta.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "16.4.0-beta.8",
3
+ "version": "16.4.0-beta.9",
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": {
@@ -39,9 +39,9 @@
39
39
  "@babel/preset-env": "^7.15.0",
40
40
  "@babel/preset-typescript": "^7.15.0",
41
41
  "@babel/runtime": "^7.14.8",
42
- "@nrwl/js": "16.4.0-beta.8",
43
- "@nx/devkit": "16.4.0-beta.8",
44
- "@nx/workspace": "16.4.0-beta.8",
42
+ "@nrwl/js": "16.4.0-beta.9",
43
+ "@nx/devkit": "16.4.0-beta.9",
44
+ "@nx/workspace": "16.4.0-beta.9",
45
45
  "@phenomnomnominal/tsquery": "~5.0.1",
46
46
  "babel-plugin-const-enum": "^1.0.1",
47
47
  "babel-plugin-macros": "^2.8.0",
@@ -69,5 +69,5 @@
69
69
  "access": "public"
70
70
  },
71
71
  "types": "./src/index.d.ts",
72
- "gitHead": "a6589ab111fc01fd4d2cd215c31bfcff004dfc00"
72
+ "gitHead": "b7fbc25d5be1789d42805e2254cf4a6070889157"
73
73
  }
@@ -0,0 +1 @@
1
+ export * from '../../src/plugins/jest/start-local-registry';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("../../src/plugins/jest/start-local-registry"), exports);
@@ -21,8 +21,12 @@ function verdaccioExecutor(options, context) {
21
21
  catch (e) {
22
22
  throw new Error('Verdaccio is not installed. Please run `npm install verdaccio` or `yarn add verdaccio`');
23
23
  }
24
- if (options.clear && options.storage && (0, fs_extra_1.existsSync)(options.storage)) {
25
- (0, fs_extra_1.removeSync)(options.storage);
24
+ if (options.storage) {
25
+ options.storage = (0, path_1.resolve)(context.root, options.storage);
26
+ if (options.clear && (0, fs_extra_1.existsSync)(options.storage)) {
27
+ (0, fs_extra_1.rmSync)(options.storage, { recursive: true, force: true });
28
+ console.log(`Cleared local registry storage folder ${options.storage}`);
29
+ }
26
30
  }
27
31
  const cleanupFunctions = options.location === 'none' ? [] : [setupNpm(options), setupYarn(options)];
28
32
  const processExitListener = (signal) => {
@@ -68,19 +72,7 @@ function startVerdaccio(options, workspaceRoot) {
68
72
  env: Object.assign(Object.assign(Object.assign({}, process.env), { VERDACCIO_HANDLE_KILL_SIGNALS: 'true' }), (options.storage
69
73
  ? { VERDACCIO_STORAGE_PATH: options.storage }
70
74
  : {})),
71
- stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
72
- });
73
- childProcess.stdout.on('data', (data) => {
74
- process.stdout.write(data);
75
- });
76
- childProcess.stderr.on('data', (data) => {
77
- if (data.includes('VerdaccioWarning') ||
78
- data.includes('DeprecationWarning')) {
79
- process.stdout.write(data);
80
- }
81
- else {
82
- reject(data);
83
- }
75
+ stdio: 'inherit',
84
76
  });
85
77
  childProcess.on('error', (err) => {
86
78
  reject(err);
@@ -8,7 +8,7 @@ auth:
8
8
  # a list of other known repositories we can talk to
9
9
  uplinks:
10
10
  npmjs:
11
- url: https://registry.npmjs.org/
11
+ url: <%= npmUplinkRegistry %>
12
12
  maxage: 60m
13
13
 
14
14
  packages:
@@ -5,10 +5,14 @@ const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const path = require("path");
7
7
  const versions_1 = require("../../utils/versions");
8
+ const child_process_1 = require("child_process");
8
9
  function setupVerdaccio(tree, options) {
10
+ var _a, _b, _c;
9
11
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
12
  if (!tree.exists('.verdaccio/config.yml')) {
11
- (0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files'), '.verdaccio', {});
13
+ (0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files'), '.verdaccio', {
14
+ npmUplinkRegistry: (_c = (_b = (_a = (0, child_process_1.execSync)('npm config get registry')) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : 'https://registry.npmjs.org',
15
+ });
12
16
  }
13
17
  const verdaccioTarget = {
14
18
  executor: '@nx/js:verdaccio',
@@ -0,0 +1,12 @@
1
+ /**
2
+ * This function is used to start a local registry for testing purposes.
3
+ * @param localRegistryTarget the target to run to start the local registry e.g. workspace:local-registry
4
+ * @param storage the storage location for the local registry
5
+ * @param verbose whether to log verbose output
6
+ */
7
+ export declare function startLocalRegistry({ localRegistryTarget, storage, verbose, }: {
8
+ localRegistryTarget: string;
9
+ storage?: string;
10
+ verbose?: boolean;
11
+ }): Promise<() => void>;
12
+ export default startLocalRegistry;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startLocalRegistry = void 0;
4
+ const child_process_1 = require("child_process");
5
+ /**
6
+ * This function is used to start a local registry for testing purposes.
7
+ * @param localRegistryTarget the target to run to start the local registry e.g. workspace:local-registry
8
+ * @param storage the storage location for the local registry
9
+ * @param verbose whether to log verbose output
10
+ */
11
+ function startLocalRegistry({ localRegistryTarget, storage, verbose, }) {
12
+ if (!localRegistryTarget) {
13
+ throw new Error(`localRegistryTarget is required`);
14
+ }
15
+ return new Promise((resolve, reject) => {
16
+ var _a, _b;
17
+ const childProcess = (0, child_process_1.fork)(require.resolve('nx'), [
18
+ ...`run ${localRegistryTarget} --location none --clear true`.split(' '),
19
+ ...(storage ? [`--storage`, storage] : []),
20
+ ], { stdio: 'pipe' });
21
+ const listener = (data) => {
22
+ var _a, _b, _c;
23
+ if (verbose) {
24
+ process.stdout.write(data);
25
+ }
26
+ if (data.toString().includes('http://localhost:')) {
27
+ const port = parseInt((_b = (_a = data.toString().match(/localhost:(?<port>\d+)/)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.port);
28
+ console.log('Local registry started on port ' + port);
29
+ const registry = `http://localhost:${port}`;
30
+ process.env.npm_config_registry = registry;
31
+ process.env.YARN_REGISTRY = registry;
32
+ (0, child_process_1.execSync)(`npm config set //localhost:${port}/:_authToken "secretVerdaccioToken"`);
33
+ console.log('Set npm and yarn config registry to ' + registry);
34
+ resolve(() => {
35
+ childProcess.kill();
36
+ (0, child_process_1.execSync)(`npm config delete //localhost:${port}/:_authToken`);
37
+ });
38
+ (_c = childProcess === null || childProcess === void 0 ? void 0 : childProcess.stdout) === null || _c === void 0 ? void 0 : _c.off('data', listener);
39
+ }
40
+ };
41
+ (_a = childProcess === null || childProcess === void 0 ? void 0 : childProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', listener);
42
+ (_b = childProcess === null || childProcess === void 0 ? void 0 : childProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
43
+ process.stderr.write(data);
44
+ });
45
+ childProcess.on('error', (err) => {
46
+ console.log('local registry error', err);
47
+ reject(err);
48
+ });
49
+ childProcess.on('exit', (code) => {
50
+ console.log('local registry exit', code);
51
+ if (code !== 0) {
52
+ reject(code);
53
+ }
54
+ else {
55
+ resolve(() => { });
56
+ }
57
+ });
58
+ });
59
+ }
60
+ exports.startLocalRegistry = startLocalRegistry;
61
+ exports.default = startLocalRegistry;
@@ -0,0 +1,5 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare function addLocalRegistryScripts(tree: Tree): {
3
+ startLocalRegistryPath: string;
4
+ stopLocalRegistryPath: string;
5
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addLocalRegistryScripts = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const startLocalRegistryScript = (localRegistryTarget) => `
6
+ /**
7
+ * This script starts a local registry for e2e testing purposes.
8
+ * It is meant to be called in jest's globalSetup.
9
+ */
10
+ import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
11
+ import { execFileSync } from 'child_process';
12
+
13
+ export default async () => {
14
+ // local registry target to run
15
+ const localRegistryTarget = '${localRegistryTarget}';
16
+ // storage folder for the local registry
17
+ const storage = './tmp/local-registry/storage';
18
+
19
+ global.stopLocalRegistry = await startLocalRegistry({
20
+ localRegistryTarget,
21
+ storage,
22
+ verbose: false,
23
+ });
24
+ const nx = require.resolve('nx');
25
+ execFileSync(
26
+ nx,
27
+ ['run-many', '--targets', 'publish', '--ver', '1.0.0', '--tag', 'e2e'],
28
+ { env: process.env, stdio: 'inherit' }
29
+ );
30
+ };
31
+ `;
32
+ const stopLocalRegistryScript = `
33
+ /**
34
+ * This script stops the local registry for e2e testing purposes.
35
+ * It is meant to be called in jest's globalTeardown.
36
+ */
37
+
38
+ export default () => {
39
+ if (global.stopLocalRegistry) {
40
+ global.stopLocalRegistry();
41
+ }
42
+ };
43
+ `;
44
+ function addLocalRegistryScripts(tree) {
45
+ const startLocalRegistryPath = 'tools/scripts/start-local-registry.ts';
46
+ const stopLocalRegistryPath = 'tools/scripts/stop-local-registry.ts';
47
+ const projectConfiguration = (0, devkit_1.readJson)(tree, 'project.json');
48
+ const localRegistryTarget = `${projectConfiguration.name}:local-registry`;
49
+ if (!tree.exists(startLocalRegistryPath)) {
50
+ tree.write(startLocalRegistryPath, startLocalRegistryScript(localRegistryTarget));
51
+ }
52
+ if (!tree.exists(stopLocalRegistryPath)) {
53
+ tree.write(stopLocalRegistryPath, stopLocalRegistryScript);
54
+ }
55
+ return { startLocalRegistryPath, stopLocalRegistryPath };
56
+ }
57
+ exports.addLocalRegistryScripts = addLocalRegistryScripts;
@@ -13,14 +13,13 @@ const publishScriptContent = `
13
13
 
14
14
  import { execSync } from 'child_process';
15
15
  import { readFileSync, writeFileSync } from 'fs';
16
- import chalk from 'chalk';
17
16
 
18
17
  import devkit from '@nx/devkit';
19
18
  const { readCachedProjectGraph } = devkit;
20
19
 
21
20
  function invariant(condition, message) {
22
21
  if (!condition) {
23
- console.error(chalk.bold.red(message));
22
+ console.error(message);
24
23
  process.exit(1);
25
24
  }
26
25
  }
@@ -59,9 +58,7 @@ try {
59
58
  json.version = version;
60
59
  writeFileSync(\`package.json\`, JSON.stringify(json, null, 2));
61
60
  } catch (e) {
62
- console.error(
63
- chalk.bold.red(\`Error reading package.json file from library build output.\`)
64
- );
61
+ console.error(\`Error reading package.json file from library build output.\`);
65
62
  }
66
63
 
67
64
  // Execute "npm publish" to publish