@nx/devkit 18.0.0-canary.20240202-ea5befb → 18.0.0

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/devkit",
3
- "version": "18.0.0-canary.20240202-ea5befb",
3
+ "version": "18.0.0",
4
4
  "private": false,
5
5
  "description": "The Nx Devkit is used to customize Nx for different technologies and use cases. It contains many utility functions for reading and writing files, updating configuration, working with Abstract Syntax Trees(ASTs), and more. Learn more about [extending Nx by leveraging the Nx Devkit](https://nx.dev/extending-nx/intro/getting-started) on our docs.",
6
6
  "repository": {
@@ -35,7 +35,7 @@
35
35
  "tslib": "^2.3.0",
36
36
  "semver": "^7.5.3",
37
37
  "yargs-parser": "21.1.1",
38
- "@nrwl/devkit": "18.0.0-canary.20240202-ea5befb"
38
+ "@nrwl/devkit": "18.0.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "nx": ">= 16 <= 18"
@@ -0,0 +1,4 @@
1
+ export declare let dynamicImport: Function;
2
+ export declare function loadConfigFile<T extends object = any>(configFilePath: string): Promise<T>;
3
+ export declare function getRootTsConfigPath(): string | null;
4
+ export declare function getRootTsConfigFileName(): string | null;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRootTsConfigFileName = exports.getRootTsConfigPath = exports.loadConfigFile = exports.dynamicImport = void 0;
4
+ const path_1 = require("path");
5
+ const fs_1 = require("fs");
6
+ const nx_1 = require("../../nx");
7
+ const { workspaceRoot, registerTsProject } = (0, nx_1.requireNx)();
8
+ exports.dynamicImport = new Function('modulePath', 'return import(modulePath);');
9
+ async function loadConfigFile(configFilePath) {
10
+ {
11
+ let module;
12
+ if ((0, path_1.extname)(configFilePath) === '.ts') {
13
+ const siblingFiles = (0, fs_1.readdirSync)((0, path_1.dirname)(configFilePath));
14
+ const tsConfigPath = siblingFiles.includes('tsconfig.json')
15
+ ? (0, path_1.join)((0, path_1.dirname)(configFilePath), 'tsconfig.json')
16
+ : getRootTsConfigPath();
17
+ if (tsConfigPath) {
18
+ const unregisterTsProject = registerTsProject(tsConfigPath, undefined,
19
+ // TODO(@AgentEnder): Remove this hack to make sure that e2e loads properly for next.js
20
+ (0, path_1.relative)(workspaceRoot, (0, path_1.dirname)(configFilePath)) === 'e2e');
21
+ try {
22
+ module = await load(configFilePath);
23
+ }
24
+ finally {
25
+ unregisterTsProject();
26
+ }
27
+ }
28
+ else {
29
+ module = await load(configFilePath);
30
+ }
31
+ }
32
+ else {
33
+ module = await load(configFilePath);
34
+ }
35
+ return module.default ?? module;
36
+ }
37
+ }
38
+ exports.loadConfigFile = loadConfigFile;
39
+ function getRootTsConfigPath() {
40
+ const tsConfigFileName = getRootTsConfigFileName();
41
+ return tsConfigFileName ? (0, path_1.join)(workspaceRoot, tsConfigFileName) : null;
42
+ }
43
+ exports.getRootTsConfigPath = getRootTsConfigPath;
44
+ function getRootTsConfigFileName() {
45
+ for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) {
46
+ const pathExists = (0, fs_1.existsSync)((0, path_1.join)(workspaceRoot, tsConfigName));
47
+ if (pathExists) {
48
+ return tsConfigName;
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+ exports.getRootTsConfigFileName = getRootTsConfigFileName;
54
+ /**
55
+ * Load the module after ensuring that the require cache is cleared.
56
+ */
57
+ async function load(path) {
58
+ // Clear cache if the path is in the cache
59
+ if (require.cache[path]) {
60
+ for (const k of Object.keys(require.cache)) {
61
+ delete require.cache[k];
62
+ }
63
+ }
64
+ try {
65
+ // Try using `require` first, which works for CJS modules.
66
+ // Modules are CJS unless it is named `.mjs` or `package.json` sets type to "module".
67
+ return require(path);
68
+ }
69
+ catch (e) {
70
+ if (e.code === 'ERR_REQUIRE_ESM') {
71
+ // If `require` fails to load ESM, try dynamic `import()`.
72
+ return await (0, exports.dynamicImport)(`${path}?t=${Date.now()}`);
73
+ }
74
+ // Re-throw all other errors
75
+ throw e;
76
+ }
77
+ }