@nx/vite 17.0.3 → 17.0.5
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 +1 -1
- package/README.md +9 -4
- package/generators.json +3 -3
- package/migrations.json +90 -0
- package/package.json +9 -7
- package/plugin.d.ts +1 -0
- package/plugin.js +21 -0
- package/plugin.js.map +1 -0
- package/plugins/nx-tsconfig-paths.plugin.js +9 -5
- package/plugins/nx-tsconfig-paths.plugin.js.map +1 -1
- package/plugins/rollup-replace-files.plugin.d.ts +3 -3
- package/plugins/rollup-replace-files.plugin.js +2 -2
- package/plugins/rollup-replace-files.plugin.js.map +1 -1
- package/src/executors/build/build.impl.d.ts +5 -1
- package/src/executors/build/build.impl.js +90 -21
- package/src/executors/build/build.impl.js.map +1 -1
- package/src/executors/build/schema.d.ts +5 -18
- package/src/executors/build/schema.json +4 -106
- package/src/executors/dev-server/dev-server.impl.js +74 -9
- package/src/executors/dev-server/dev-server.impl.js.map +1 -1
- package/src/executors/dev-server/schema.d.ts +0 -10
- package/src/executors/dev-server/schema.json +0 -63
- package/src/executors/preview-server/preview-server.impl.d.ts +1 -1
- package/src/executors/preview-server/preview-server.impl.js +79 -15
- package/src/executors/preview-server/preview-server.impl.js.map +1 -1
- package/src/executors/preview-server/schema.d.ts +0 -7
- package/src/executors/preview-server/schema.json +1 -51
- package/src/executors/test/lib/nx-reporter.d.ts +14 -0
- package/src/executors/test/lib/nx-reporter.js +40 -0
- package/src/executors/test/lib/nx-reporter.js.map +1 -0
- package/src/executors/test/lib/utils.d.ts +4 -0
- package/src/executors/test/lib/utils.js +77 -0
- package/src/executors/test/lib/utils.js.map +1 -0
- package/src/executors/test/schema.d.ts +3 -8
- package/src/executors/test/schema.json +11 -43
- package/src/executors/test/vitest.impl.js +20 -112
- package/src/executors/test/vitest.impl.js.map +1 -1
- package/src/generators/configuration/configuration.d.ts +2 -1
- package/src/generators/configuration/configuration.js +49 -87
- package/src/generators/configuration/configuration.js.map +1 -1
- package/src/generators/configuration/lib/convert-non-vite.d.ts +5 -0
- package/src/generators/configuration/lib/convert-non-vite.js +62 -0
- package/src/generators/configuration/lib/convert-non-vite.js.map +1 -0
- package/src/generators/configuration/schema.d.ts +1 -3
- package/src/generators/configuration/schema.json +0 -12
- package/src/generators/init/init.d.ts +4 -3
- package/src/generators/init/init.js +50 -67
- package/src/generators/init/init.js.map +1 -1
- package/src/generators/init/lib/utils.d.ts +6 -0
- package/src/generators/init/lib/utils.js +80 -0
- package/src/generators/init/lib/utils.js.map +1 -0
- package/src/generators/init/schema.d.ts +5 -5
- package/src/generators/init/schema.json +17 -20
- package/src/generators/vitest/files/tsconfig.spec.json__tmpl__ +2 -1
- package/src/generators/vitest/schema.d.ts +2 -1
- package/src/generators/vitest/schema.json +2 -2
- package/src/generators/vitest/vitest-generator.d.ts +2 -1
- package/src/generators/vitest/vitest-generator.js +34 -10
- package/src/generators/vitest/vitest-generator.js.map +1 -1
- package/src/migrations/update-15-3-1/update-vite-tsconfig-paths.js.map +1 -1
- package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.js +3 -17
- package/src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin.js.map +1 -1
- package/src/migrations/update-17-1-0/move-target-defaults.d.ts +2 -0
- package/src/migrations/update-17-1-0/move-target-defaults.js +77 -0
- package/src/migrations/update-17-1-0/move-target-defaults.js.map +1 -0
- package/src/migrations/update-17-2-0/lib/add-file-replacements.d.ts +2 -0
- package/src/migrations/update-17-2-0/lib/add-file-replacements.js +67 -0
- package/src/migrations/update-17-2-0/lib/add-file-replacements.js.map +1 -0
- package/src/migrations/update-17-2-0/lib/edit-build-config.d.ts +2 -0
- package/src/migrations/update-17-2-0/lib/edit-build-config.js +121 -0
- package/src/migrations/update-17-2-0/lib/edit-build-config.js.map +1 -0
- package/src/migrations/update-17-2-0/lib/edit-test-config.d.ts +2 -0
- package/src/migrations/update-17-2-0/lib/edit-test-config.js +83 -0
- package/src/migrations/update-17-2-0/lib/edit-test-config.js.map +1 -0
- package/src/migrations/update-17-2-0/update-vite-config.d.ts +5 -0
- package/src/migrations/update-17-2-0/update-vite-config.js +68 -0
- package/src/migrations/update-17-2-0/update-vite-config.js.map +1 -0
- package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.d.ts +3 -0
- package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.js +117 -0
- package/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.js.map +1 -0
- package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.d.ts +2 -0
- package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.js +45 -0
- package/src/migrations/update-17-3-0/vitest-coverage-and-reporters.js.map +1 -0
- package/src/plugins/plugin.d.ts +10 -0
- package/src/plugins/plugin.js +226 -0
- package/src/plugins/plugin.js.map +1 -0
- package/src/utils/ensure-dependencies.d.ts +8 -0
- package/src/utils/ensure-dependencies.js +34 -0
- package/src/utils/ensure-dependencies.js.map +1 -0
- package/src/utils/executor-utils.d.ts +2 -0
- package/src/utils/executor-utils.js +22 -7
- package/src/utils/executor-utils.js.map +1 -1
- package/src/utils/find-vite-config.d.ts +3 -0
- package/src/utils/find-vite-config.js +46 -0
- package/src/utils/find-vite-config.js.map +1 -0
- package/src/utils/generator-utils.d.ts +10 -12
- package/src/utils/generator-utils.js +134 -213
- package/src/utils/generator-utils.js.map +1 -1
- package/src/utils/options-utils.d.ts +3 -19
- package/src/utils/options-utils.js +25 -68
- package/src/utils/options-utils.js.map +1 -1
- package/src/utils/test-files/react-lib-non-buildable-jest.json +1 -4
- package/src/utils/test-files/react-lib-non-buildable-vitest.json +1 -4
- package/src/utils/test-files/react-mixed-project.config.json +1 -6
- package/src/utils/test-files/react-vite-project.config.json +1 -4
- package/src/utils/test-files/unknown-project.config.json +1 -4
- package/src/utils/test-utils.d.ts +1 -1
- package/src/utils/test-utils.js +10 -18
- package/src/utils/test-utils.js.map +1 -1
- package/src/utils/versions.d.ts +7 -9
- package/src/utils/versions.js +7 -15
- package/src/utils/versions.js.map +1 -1
- package/src/utils/vite-config-edit-utils.js +1 -1
- package/src/utils/vite-config-edit-utils.js.map +1 -1
- package/src/utils/test-files/react-project.config.json +0 -85
- package/src/utils/test-files/web-project.config.json +0 -72
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
<p style="text-align: center;"
|
|
1
|
+
<p style="text-align: center;">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
|
|
4
|
+
<img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
2
7
|
|
|
3
8
|
<div style="text-align: center;">
|
|
4
9
|
|
|
@@ -15,9 +20,9 @@
|
|
|
15
20
|
|
|
16
21
|
<hr>
|
|
17
22
|
|
|
18
|
-
# Nx: Smart
|
|
23
|
+
# Nx: Smart Monorepos · Fast CI
|
|
19
24
|
|
|
20
|
-
Nx is a
|
|
25
|
+
Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
|
|
21
26
|
|
|
22
27
|
This package is a [Vite plugin for Nx](https://nx.dev/packages/vite).
|
|
23
28
|
|
|
@@ -59,5 +64,5 @@ npx nx@latest init
|
|
|
59
64
|
- [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
|
|
60
65
|
|
|
61
66
|
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
|
62
|
-
width="100%" alt="Nx - Smart
|
|
67
|
+
width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
|
|
63
68
|
|
package/generators.json
CHANGED
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
"version": "0.1",
|
|
4
4
|
"generators": {
|
|
5
5
|
"init": {
|
|
6
|
-
"factory": "./src/generators/init/init",
|
|
6
|
+
"factory": "./src/generators/init/init#initGeneratorInternal",
|
|
7
7
|
"schema": "./src/generators/init/schema.json",
|
|
8
8
|
"description": "Initialize Vite in the workspace.",
|
|
9
9
|
"aliases": ["ng-add"],
|
|
10
10
|
"hidden": true
|
|
11
11
|
},
|
|
12
12
|
"configuration": {
|
|
13
|
-
"factory": "./src/generators/configuration/configuration",
|
|
13
|
+
"factory": "./src/generators/configuration/configuration#viteConfigurationGeneratorInternal",
|
|
14
14
|
"schema": "./src/generators/configuration/schema.json",
|
|
15
15
|
"description": "Add Vite configuration to an application.",
|
|
16
16
|
"aliases": ["config"],
|
|
17
17
|
"hidden": false
|
|
18
18
|
},
|
|
19
19
|
"vitest": {
|
|
20
|
-
"factory": "./src/generators/vitest/vitest-generator",
|
|
20
|
+
"factory": "./src/generators/vitest/vitest-generator#vitestGeneratorInternal",
|
|
21
21
|
"schema": "./src/generators/vitest/schema.json",
|
|
22
22
|
"description": "Generate a vitest configuration"
|
|
23
23
|
}
|
package/migrations.json
CHANGED
|
@@ -35,9 +35,99 @@
|
|
|
35
35
|
"description": "Change vite-tsconfig-paths plugin for first party nx-vite-tsconfig-paths plugin",
|
|
36
36
|
"cli": "nx",
|
|
37
37
|
"implementation": "./src/migrations/update-16-6-0-change-ts-paths-plugin/change-ts-paths-plugin"
|
|
38
|
+
},
|
|
39
|
+
"move-target-defaults": {
|
|
40
|
+
"version": "17.1.0-beta.2",
|
|
41
|
+
"description": "Move target defaults",
|
|
42
|
+
"implementation": "./src/migrations/update-17-1-0/move-target-defaults"
|
|
43
|
+
},
|
|
44
|
+
"update-vite-config": {
|
|
45
|
+
"version": "17.2.0-beta.10",
|
|
46
|
+
"description": "Update vite config.",
|
|
47
|
+
"implementation": "./src/migrations/update-17-2-0/update-vite-config"
|
|
48
|
+
},
|
|
49
|
+
"vitest-coverage-and-reporters": {
|
|
50
|
+
"version": "17.3.0-beta.0",
|
|
51
|
+
"description": "Move the vitest coverage thresholds in their own object if exists and add reporters.",
|
|
52
|
+
"implementation": "./src/migrations/update-17-3-0/vitest-coverage-and-reporters"
|
|
38
53
|
}
|
|
39
54
|
},
|
|
40
55
|
"packageJsonUpdates": {
|
|
56
|
+
"18.1.0": {
|
|
57
|
+
"version": "18.1.0-beta.1",
|
|
58
|
+
"packages": {
|
|
59
|
+
"vitest": {
|
|
60
|
+
"version": "^1.3.1",
|
|
61
|
+
"alwaysAddToPackageJson": false
|
|
62
|
+
},
|
|
63
|
+
"@vitest/coverage-v8": {
|
|
64
|
+
"version": "^1.3.1",
|
|
65
|
+
"alwaysAddToPackageJson": false
|
|
66
|
+
},
|
|
67
|
+
"@vitest/ui": {
|
|
68
|
+
"version": "^1.3.1",
|
|
69
|
+
"alwaysAddToPackageJson": false
|
|
70
|
+
},
|
|
71
|
+
"@vitest/coverage-istanbul": {
|
|
72
|
+
"version": "^1.3.1",
|
|
73
|
+
"alwaysAddToPackageJson": false
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"17.3.0": {
|
|
78
|
+
"version": "17.3.0-beta.0",
|
|
79
|
+
"packages": {
|
|
80
|
+
"vitest": {
|
|
81
|
+
"version": "^1.0.4",
|
|
82
|
+
"alwaysAddToPackageJson": false
|
|
83
|
+
},
|
|
84
|
+
"@vitest/coverage-v8": {
|
|
85
|
+
"version": "^1.0.4",
|
|
86
|
+
"alwaysAddToPackageJson": false
|
|
87
|
+
},
|
|
88
|
+
"@vitest/ui": {
|
|
89
|
+
"version": "^1.0.4",
|
|
90
|
+
"alwaysAddToPackageJson": false
|
|
91
|
+
},
|
|
92
|
+
"@vitest/coverage-istanbul": {
|
|
93
|
+
"version": "^1.0.4",
|
|
94
|
+
"alwaysAddToPackageJson": false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"17.2.0": {
|
|
99
|
+
"version": "17.2.0-beta.2",
|
|
100
|
+
"packages": {
|
|
101
|
+
"vite": {
|
|
102
|
+
"version": "^5.0.0",
|
|
103
|
+
"alwaysAddToPackageJson": false
|
|
104
|
+
},
|
|
105
|
+
"@vitejs/plugin-react": {
|
|
106
|
+
"version": "^4.2.0",
|
|
107
|
+
"alwaysAddToPackageJson": false
|
|
108
|
+
},
|
|
109
|
+
"@vitejs/plugin-react-swc": {
|
|
110
|
+
"version": "^3.5.0",
|
|
111
|
+
"alwaysAddToPackageJson": false
|
|
112
|
+
},
|
|
113
|
+
"vitest": {
|
|
114
|
+
"version": "~0.34.6",
|
|
115
|
+
"alwaysAddToPackageJson": false
|
|
116
|
+
},
|
|
117
|
+
"@vitest/coverage-v8": {
|
|
118
|
+
"version": "~0.34.6",
|
|
119
|
+
"alwaysAddToPackageJson": false
|
|
120
|
+
},
|
|
121
|
+
"@vitest/ui": {
|
|
122
|
+
"version": "~0.34.6",
|
|
123
|
+
"alwaysAddToPackageJson": false
|
|
124
|
+
},
|
|
125
|
+
"@vitest/coverage-istanbul": {
|
|
126
|
+
"version": "~0.34.6",
|
|
127
|
+
"alwaysAddToPackageJson": false
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
41
131
|
"16.4.0-beta.7": {
|
|
42
132
|
"version": "16.4.0-beta.7",
|
|
43
133
|
"packages": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vite",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.0.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for building and testing applications using Vite",
|
|
6
6
|
"repository": {
|
|
@@ -29,23 +29,24 @@
|
|
|
29
29
|
"migrations": "./migrations.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@nx/devkit": "17.0.5",
|
|
32
33
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
33
34
|
"@swc/helpers": "~0.5.0",
|
|
34
35
|
"enquirer": "~2.3.6",
|
|
35
|
-
"@nx/
|
|
36
|
-
"@nx/js": "17.0.3",
|
|
36
|
+
"@nx/js": "17.0.5",
|
|
37
37
|
"tsconfig-paths": "^4.1.2",
|
|
38
|
-
"@nrwl/vite": "17.0.
|
|
38
|
+
"@nrwl/vite": "17.0.5"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"vite": "^
|
|
42
|
-
"vitest": "
|
|
41
|
+
"vite": "^5.0.0",
|
|
42
|
+
"vitest": "^1.3.1"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"exports": {
|
|
48
48
|
".": "./index.js",
|
|
49
|
+
"./plugin": "./plugin.js",
|
|
49
50
|
"./package.json": "./package.json",
|
|
50
51
|
"./migrations.json": "./migrations.json",
|
|
51
52
|
"./generators.json": "./generators.json",
|
|
@@ -54,7 +55,8 @@
|
|
|
54
55
|
"./src/executors/*/schema.json": "./src/executors/*/schema.json",
|
|
55
56
|
"./src/executors/*.impl": "./src/executors/*.impl.js",
|
|
56
57
|
"./src/executors/*/compat": "./src/executors/*/compat.js",
|
|
57
|
-
"./plugins/nx-tsconfig-paths.plugin": "./plugins/nx-tsconfig-paths.plugin.js"
|
|
58
|
+
"./plugins/nx-tsconfig-paths.plugin": "./plugins/nx-tsconfig-paths.plugin.js",
|
|
59
|
+
"./plugins/rollup-replace-files.plugin": "./plugins/rollup-replace-files.plugin.js"
|
|
58
60
|
},
|
|
59
61
|
"type": "commonjs"
|
|
60
62
|
}
|
package/plugin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createNodes, VitePluginOptions, createDependencies, } from './src/plugins/plugin';
|
package/plugin.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export(target, all) {
|
|
3
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: all[name]
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
_export(exports, {
|
|
9
|
+
createNodes: function() {
|
|
10
|
+
return _plugin.createNodes;
|
|
11
|
+
},
|
|
12
|
+
VitePluginOptions: function() {
|
|
13
|
+
return _plugin.VitePluginOptions;
|
|
14
|
+
},
|
|
15
|
+
createDependencies: function() {
|
|
16
|
+
return _plugin.createDependencies;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _plugin = require("./src/plugins/plugin");
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=plugin.js.map
|
package/plugin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../packages/vite/plugin.ts"],"sourcesContent":["export {\n createNodes,\n VitePluginOptions,\n createDependencies,\n} from './src/plugins/plugin';\n"],"names":["createNodes","VitePluginOptions","createDependencies"],"mappings":";;;;;;;;IACEA,WAAW;eAAXA,mBAAW;;IACXC,iBAAiB;eAAjBA,yBAAiB;;IACjBC,kBAAkB;eAAlBA,0BAAkB;;;wBACb"}
|
|
@@ -109,17 +109,21 @@ There should at least be a tsconfig.base.json or tsconfig.json in the root of th
|
|
|
109
109
|
const paths = tsconfig.paths[alias];
|
|
110
110
|
const normalizedImport = alias.replace(/\/\*$/, '');
|
|
111
111
|
if (importPath.startsWith(normalizedImport)) {
|
|
112
|
-
const
|
|
113
|
-
resolvedFile = findFile(importPath.replace(normalizedImport,
|
|
112
|
+
const joinedPath = (0, _devkit.joinPathFragments)(tsconfig.absoluteBaseUrl, paths[0].replace(/\/\*$/, ''));
|
|
113
|
+
resolvedFile = findFile(importPath.replace(normalizedImport, joinedPath));
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
return resolvedFile;
|
|
117
117
|
}
|
|
118
118
|
function findFile(path) {
|
|
119
119
|
for (const ext of options.extensions){
|
|
120
|
-
const
|
|
121
|
-
if ((0, _nodefs.existsSync)(
|
|
122
|
-
return
|
|
120
|
+
const resolvedPath = (0, _nodepath.resolve)(path + ext);
|
|
121
|
+
if ((0, _nodefs.existsSync)(resolvedPath)) {
|
|
122
|
+
return resolvedPath;
|
|
123
|
+
}
|
|
124
|
+
const resolvedIndexPath = (0, _nodepath.resolve)(path, `index${ext}`);
|
|
125
|
+
if ((0, _nodefs.existsSync)(resolvedIndexPath)) {
|
|
126
|
+
return resolvedIndexPath;
|
|
123
127
|
}
|
|
124
128
|
}
|
|
125
129
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/vite/plugins/nx-tsconfig-paths.plugin.ts"],"sourcesContent":["import { stripIndents, workspaceRoot } from '@nx/devkit';\nimport { existsSync } from 'node:fs';\nimport { relative, join, resolve } from 'node:path';\nimport {\n loadConfig,\n createMatchPath,\n MatchPath,\n ConfigLoaderSuccessResult,\n} from 'tsconfig-paths';\n\nexport interface nxViteTsPathsOptions {\n /**\n * Enable debug logging\n * @default false\n **/\n debug?: boolean;\n /**\n * export fields in package.json to use for resolving\n * @default [['exports', '.', 'import'], 'module', 'main']\n *\n * fallback resolution will use ['main', 'module']\n **/\n mainFields?: (string | string[])[];\n /**\n * extensions to check when resolving files when package.json resolution fails\n * @default ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs', '.cjs']\n **/\n extensions?: string[];\n}\n\nexport function nxViteTsPaths(options: nxViteTsPathsOptions = {}) {\n let matchTsPathEsm: MatchPath;\n let matchTsPathFallback: MatchPath | undefined;\n let tsConfigPathsEsm: ConfigLoaderSuccessResult;\n let tsConfigPathsFallback: ConfigLoaderSuccessResult;\n\n options.extensions ??= [\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.json',\n '.mjs',\n '.cjs',\n ];\n options.mainFields ??= [['exports', '.', 'import'], 'module', 'main'];\n\n return {\n name: 'nx-vite-ts-paths',\n configResolved(config: any) {\n const projectRoot = config.root;\n const projectRootFromWorkspaceRoot = relative(workspaceRoot, projectRoot);\n\n const foundTsConfigPath = getTsConfig(\n join(\n workspaceRoot,\n 'tmp',\n projectRootFromWorkspaceRoot,\n 'tsconfig.generated.json'\n )\n );\n if (!foundTsConfigPath) {\n throw new Error(stripIndents`Unable to find a tsconfig in the workspace! \nThere should at least be a tsconfig.base.json or tsconfig.json in the root of the workspace ${workspaceRoot}`);\n }\n const parsed = loadConfig(foundTsConfigPath);\n\n logIt('first parsed tsconfig: ', parsed);\n if (parsed.resultType === 'failed') {\n throw new Error(`Failed loading tsonfig at ${foundTsConfigPath}`);\n }\n tsConfigPathsEsm = parsed;\n\n matchTsPathEsm = createMatchPath(\n parsed.absoluteBaseUrl,\n parsed.paths,\n options.mainFields\n );\n\n const rootLevelTsConfig = getTsConfig(\n join(workspaceRoot, 'tsconfig.base.json')\n );\n const rootLevelParsed = loadConfig(rootLevelTsConfig);\n logIt('fallback parsed tsconfig: ', rootLevelParsed);\n if (rootLevelParsed.resultType === 'success') {\n tsConfigPathsFallback = rootLevelParsed;\n matchTsPathFallback = createMatchPath(\n rootLevelParsed.absoluteBaseUrl,\n rootLevelParsed.paths,\n ['main', 'module']\n );\n }\n },\n resolveId(importPath: string) {\n let resolvedFile: string;\n try {\n resolvedFile = matchTsPathEsm(importPath);\n } catch (e) {\n logIt('Using fallback path matching.');\n resolvedFile = matchTsPathFallback?.(importPath);\n }\n\n if (!resolvedFile) {\n if (tsConfigPathsEsm || tsConfigPathsFallback) {\n logIt(\n `Unable to resolve ${importPath} with tsconfig paths. Using fallback file matching.`\n );\n resolvedFile =\n loadFileFromPaths(tsConfigPathsEsm, importPath) ||\n loadFileFromPaths(tsConfigPathsFallback, importPath);\n } else {\n logIt(`Unable to resolve ${importPath} with tsconfig paths`);\n }\n }\n\n logIt(`Resolved ${importPath} to ${resolvedFile}`);\n // Returning null defers to other resolveId functions and eventually the default resolution behavior\n // https://rollupjs.org/plugin-development/#resolveid\n return resolvedFile || null;\n },\n };\n\n function getTsConfig(preferredTsConfigPath: string): string {\n return [\n resolve(preferredTsConfigPath),\n resolve(join(workspaceRoot, 'tsconfig.base.json')),\n resolve(join(workspaceRoot, 'tsconfig.json')),\n ].find((tsPath) => {\n if (existsSync(tsPath)) {\n logIt('Found tsconfig at', tsPath);\n return tsPath;\n }\n });\n }\n\n function logIt(...msg: any[]) {\n if (process.env.NX_VERBOSE_LOGGING === 'true' || options?.debug) {\n console.debug('\\n[Nx Vite TsPaths]', ...msg);\n }\n }\n\n function loadFileFromPaths(\n tsconfig: ConfigLoaderSuccessResult,\n importPath: string\n ) {\n logIt(\n `Trying to resolve file from config in ${tsconfig.configFileAbsolutePath}`\n );\n let resolvedFile: string;\n for (const alias in tsconfig.paths) {\n const paths = tsconfig.paths[alias];\n\n const normalizedImport = alias.replace(/\\/\\*$/, '');\n\n if (importPath.startsWith(normalizedImport)) {\n const
|
|
1
|
+
{"version":3,"sources":["../../../../packages/vite/plugins/nx-tsconfig-paths.plugin.ts"],"sourcesContent":["import { joinPathFragments, stripIndents, workspaceRoot } from '@nx/devkit';\nimport { existsSync } from 'node:fs';\nimport { relative, join, resolve } from 'node:path';\nimport {\n loadConfig,\n createMatchPath,\n MatchPath,\n ConfigLoaderSuccessResult,\n} from 'tsconfig-paths';\n\nexport interface nxViteTsPathsOptions {\n /**\n * Enable debug logging\n * @default false\n **/\n debug?: boolean;\n /**\n * export fields in package.json to use for resolving\n * @default [['exports', '.', 'import'], 'module', 'main']\n *\n * fallback resolution will use ['main', 'module']\n **/\n mainFields?: (string | string[])[];\n /**\n * extensions to check when resolving files when package.json resolution fails\n * @default ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs', '.cjs']\n **/\n extensions?: string[];\n}\n\nexport function nxViteTsPaths(options: nxViteTsPathsOptions = {}) {\n let matchTsPathEsm: MatchPath;\n let matchTsPathFallback: MatchPath | undefined;\n let tsConfigPathsEsm: ConfigLoaderSuccessResult;\n let tsConfigPathsFallback: ConfigLoaderSuccessResult;\n\n options.extensions ??= [\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.json',\n '.mjs',\n '.cjs',\n ];\n options.mainFields ??= [['exports', '.', 'import'], 'module', 'main'];\n\n return {\n name: 'nx-vite-ts-paths',\n configResolved(config: any) {\n const projectRoot = config.root;\n const projectRootFromWorkspaceRoot = relative(workspaceRoot, projectRoot);\n\n const foundTsConfigPath = getTsConfig(\n join(\n workspaceRoot,\n 'tmp',\n projectRootFromWorkspaceRoot,\n 'tsconfig.generated.json'\n )\n );\n if (!foundTsConfigPath) {\n throw new Error(stripIndents`Unable to find a tsconfig in the workspace! \nThere should at least be a tsconfig.base.json or tsconfig.json in the root of the workspace ${workspaceRoot}`);\n }\n const parsed = loadConfig(foundTsConfigPath);\n\n logIt('first parsed tsconfig: ', parsed);\n if (parsed.resultType === 'failed') {\n throw new Error(`Failed loading tsonfig at ${foundTsConfigPath}`);\n }\n tsConfigPathsEsm = parsed;\n\n matchTsPathEsm = createMatchPath(\n parsed.absoluteBaseUrl,\n parsed.paths,\n options.mainFields\n );\n\n const rootLevelTsConfig = getTsConfig(\n join(workspaceRoot, 'tsconfig.base.json')\n );\n const rootLevelParsed = loadConfig(rootLevelTsConfig);\n logIt('fallback parsed tsconfig: ', rootLevelParsed);\n if (rootLevelParsed.resultType === 'success') {\n tsConfigPathsFallback = rootLevelParsed;\n matchTsPathFallback = createMatchPath(\n rootLevelParsed.absoluteBaseUrl,\n rootLevelParsed.paths,\n ['main', 'module']\n );\n }\n },\n resolveId(importPath: string) {\n let resolvedFile: string;\n try {\n resolvedFile = matchTsPathEsm(importPath);\n } catch (e) {\n logIt('Using fallback path matching.');\n resolvedFile = matchTsPathFallback?.(importPath);\n }\n\n if (!resolvedFile) {\n if (tsConfigPathsEsm || tsConfigPathsFallback) {\n logIt(\n `Unable to resolve ${importPath} with tsconfig paths. Using fallback file matching.`\n );\n resolvedFile =\n loadFileFromPaths(tsConfigPathsEsm, importPath) ||\n loadFileFromPaths(tsConfigPathsFallback, importPath);\n } else {\n logIt(`Unable to resolve ${importPath} with tsconfig paths`);\n }\n }\n\n logIt(`Resolved ${importPath} to ${resolvedFile}`);\n // Returning null defers to other resolveId functions and eventually the default resolution behavior\n // https://rollupjs.org/plugin-development/#resolveid\n return resolvedFile || null;\n },\n };\n\n function getTsConfig(preferredTsConfigPath: string): string {\n return [\n resolve(preferredTsConfigPath),\n resolve(join(workspaceRoot, 'tsconfig.base.json')),\n resolve(join(workspaceRoot, 'tsconfig.json')),\n ].find((tsPath) => {\n if (existsSync(tsPath)) {\n logIt('Found tsconfig at', tsPath);\n return tsPath;\n }\n });\n }\n\n function logIt(...msg: any[]) {\n if (process.env.NX_VERBOSE_LOGGING === 'true' || options?.debug) {\n console.debug('\\n[Nx Vite TsPaths]', ...msg);\n }\n }\n\n function loadFileFromPaths(\n tsconfig: ConfigLoaderSuccessResult,\n importPath: string\n ) {\n logIt(\n `Trying to resolve file from config in ${tsconfig.configFileAbsolutePath}`\n );\n let resolvedFile: string;\n for (const alias in tsconfig.paths) {\n const paths = tsconfig.paths[alias];\n\n const normalizedImport = alias.replace(/\\/\\*$/, '');\n\n if (importPath.startsWith(normalizedImport)) {\n const joinedPath = joinPathFragments(\n tsconfig.absoluteBaseUrl,\n paths[0].replace(/\\/\\*$/, '')\n );\n\n resolvedFile = findFile(\n importPath.replace(normalizedImport, joinedPath)\n );\n }\n }\n\n return resolvedFile;\n }\n\n function findFile(path: string): string {\n for (const ext of options.extensions) {\n const resolvedPath = resolve(path + ext);\n if (existsSync(resolvedPath)) {\n return resolvedPath;\n }\n\n const resolvedIndexPath = resolve(path, `index${ext}`);\n if (existsSync(resolvedIndexPath)) {\n return resolvedIndexPath;\n }\n }\n }\n}\n"],"names":["nxViteTsPaths","options","matchTsPathEsm","matchTsPathFallback","tsConfigPathsEsm","tsConfigPathsFallback","extensions","mainFields","name","configResolved","config","projectRoot","root","projectRootFromWorkspaceRoot","relative","workspaceRoot","foundTsConfigPath","getTsConfig","join","Error","stripIndents","parsed","loadConfig","logIt","resultType","createMatchPath","absoluteBaseUrl","paths","rootLevelTsConfig","rootLevelParsed","resolveId","importPath","resolvedFile","e","loadFileFromPaths","preferredTsConfigPath","resolve","find","tsPath","existsSync","msg","process","env","NX_VERBOSE_LOGGING","debug","console","tsconfig","configFileAbsolutePath","alias","normalizedImport","replace","startsWith","joinedPath","joinPathFragments","findFile","path","ext","resolvedPath","resolvedIndexPath"],"mappings":";+BA8BgBA;;;eAAAA;;;wBA9B+C;wBACpC;0BACa;+BAMjC;AAsBA,SAASA,cAAcC,UAAgC,CAAC,CAAC;QAM9DA,UASAA;IAdA,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;;IAEJJ,gBAAAA,WAAAA,SAAQK,oCAARL,SAAQK,aAAe;QACrB;QACA;QACA;QACA;QACA;QACA;QACA;KACD;;IACDL,gBAAAA,YAAAA,SAAQM,oCAARN,UAAQM,aAAe;QAAC;YAAC;YAAW;YAAK;SAAS;QAAE;QAAU;KAAO;IAErE,OAAO;QACLC,MAAM;QACNC,gBAAeC,MAAW;YACxB,MAAMC,cAAcD,OAAOE,IAAI;YAC/B,MAAMC,+BAA+BC,IAAAA,kBAAQ,EAACC,qBAAa,EAAEJ;YAE7D,MAAMK,oBAAoBC,YACxBC,IAAAA,cAAI,EACFH,qBAAa,EACb,OACAF,8BACA;YAGJ,IAAI,CAACG,mBAAmB;gBACtB,MAAM,IAAIG,MAAMC,IAAAA,oBAAY,CAAA,CAAC;4FACuD,EAAEL,qBAAa,CAAC,CAAC;YACvG;YACA,MAAMM,SAASC,IAAAA,yBAAU,EAACN;YAE1BO,MAAM,2BAA2BF;YACjC,IAAIA,OAAOG,UAAU,KAAK,UAAU;gBAClC,MAAM,IAAIL,MAAM,CAAC,0BAA0B,EAAEH,kBAAkB,CAAC;YAClE;YACAZ,mBAAmBiB;YAEnBnB,iBAAiBuB,IAAAA,8BAAe,EAC9BJ,OAAOK,eAAe,EACtBL,OAAOM,KAAK,EACZ1B,QAAQM,UAAU;YAGpB,MAAMqB,oBAAoBX,Y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WAAU1C,2BAAAA,QAAS2C,KAAK,GAAE;YAC/DC,QAAQD,KAAK,CAAC,0BAA0BJ;QAC1C;IACF;IAEA,SAASN,kBACPY,QAAmC,EACnCf,UAAkB;QAElBR,MACE,CAAC,sCAAsC,EAAEuB,SAASC,sBAAsB,CAAC,CAAC;QAE5E,IAAIf;QACJ,IAAK,MAAMgB,SAASF,SAASnB,KAAK,CAAE;YAClC,MAAMA,QAAQmB,SAASnB,KAAK,CAACqB,MAAM;YAEnC,MAAMC,mBAAmBD,MAAME,OAAO,CAAC,SAAS;YAEhD,IAAInB,WAAWoB,UAAU,CAACF,mBAAmB;gBAC3C,MAAMG,aAAaC,IAAAA,yBAAiB,EAClCP,SAASpB,eAAe,EACxBC,KAAK,CAAC,EAAE,CAACuB,OAAO,CAAC,SAAS;gBAG5BlB,eAAesB,SACbvB,WAAWmB,OAAO,CAACD,kBAAkBG;YAEzC;QACF;QAEA,OAAOpB;IACT;IAEA,SAASsB,SAASC,IAAY;QAC5B,KAAK,MAAMC,OAAOvD,QAAQK,UAAU,CAAE;YACpC,MAAMmD,eAAerB,IAAAA,iBAAO,EAACmB,OAAOC;YACpC,IAAIjB,IAAAA,kBAAU,EAACkB,eAAe;gBAC5B,OAAOA;YACT;YAEA,MAAMC,oBAAoBtB,IAAAA,iBAAO,EAACmB,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC;YACrD,IAAIjB,IAAAA,kBAAU,EAACmB,oBAAoB;gBACjC,OAAOA;YACT;QACF;IACF;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @function replaceFiles
|
|
3
3
|
* @param {FileReplacement[]} replacements
|
|
4
|
-
* @return {({name: "rollup-plugin-replace-files", enforce: "pre", Promise<resolveId>})}
|
|
4
|
+
* @return {({name: "rollup-plugin-replace-files", enforce: "pre" | "post" | undefined, Promise<resolveId>})}
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export declare function replaceFiles(replacements: FileReplacement[]): {
|
|
7
7
|
name: string;
|
|
8
|
-
enforce:
|
|
8
|
+
enforce: 'pre' | 'post' | undefined;
|
|
9
9
|
resolveId(source: any, importer: any, options: any): Promise<{
|
|
10
10
|
id: string;
|
|
11
11
|
}>;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @function replaceFiles
|
|
4
4
|
* @param {FileReplacement[]} replacements
|
|
5
|
-
* @return {({name: "rollup-plugin-replace-files", enforce: "pre", Promise<resolveId>})}
|
|
5
|
+
* @return {({name: "rollup-plugin-replace-files", enforce: "pre" | "post" | undefined, Promise<resolveId>})}
|
|
6
6
|
*/ "use strict";
|
|
7
|
-
Object.defineProperty(exports, "
|
|
7
|
+
Object.defineProperty(exports, "replaceFiles", {
|
|
8
8
|
enumerable: true,
|
|
9
9
|
get: function() {
|
|
10
10
|
return replaceFiles;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/vite/plugins/rollup-replace-files.plugin.ts"],"sourcesContent":["// source: https://github.com/Myrmod/vitejs-theming/blob/master/build-plugins/rollup/replace-files.js\n\n/**\n * @function replaceFiles\n * @param {FileReplacement[]} replacements\n * @return {({name: \"rollup-plugin-replace-files\", enforce: \"pre\", Promise<resolveId>})}\n */\nexport
|
|
1
|
+
{"version":3,"sources":["../../../../packages/vite/plugins/rollup-replace-files.plugin.ts"],"sourcesContent":["// source: https://github.com/Myrmod/vitejs-theming/blob/master/build-plugins/rollup/replace-files.js\n\n/**\n * @function replaceFiles\n * @param {FileReplacement[]} replacements\n * @return {({name: \"rollup-plugin-replace-files\", enforce: \"pre\" | \"post\" | undefined, Promise<resolveId>})}\n */\nexport function replaceFiles(replacements: FileReplacement[]): {\n name: string;\n enforce: 'pre' | 'post' | undefined;\n resolveId(\n source: any,\n importer: any,\n options: any\n ): Promise<{\n id: string;\n }>;\n} {\n if (!replacements?.length) {\n return null;\n }\n return {\n name: 'rollup-plugin-replace-files',\n enforce: 'pre',\n async resolveId(source, importer, options) {\n const resolved = await this.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n /**\n * The reason we're using endsWith here is because the resolved id\n * will be the absolute path to the file. We want to check if the\n * file ends with the file we're trying to replace, which will be essentially\n * the path from the root of our workspace.\n */\n\n const foundReplace = replacements.find((replacement) =>\n resolved?.id?.endsWith(replacement.replace)\n );\n if (foundReplace) {\n console.info(\n `replace \"${foundReplace.replace}\" with \"${foundReplace.with}\"`\n );\n try {\n // return new file content\n return {\n id: foundReplace.with,\n };\n } catch (err) {\n console.error(err);\n return null;\n }\n }\n return null;\n },\n };\n}\n\nexport interface FileReplacement {\n replace: string;\n with: string;\n}\n"],"names":["replaceFiles","replacements","length","name","enforce","resolveId","source","importer","options","resolved","resolve","skipSelf","foundReplace","find","replacement","id","endsWith","replace","console","info","with","err","error"],"mappings":"AAAA,qGAAqG;AAErG;;;;CAIC;+BACeA;;;eAAAA;;;;AAAT,SAASA,aAAaC,YAA+B;IAW1D,IAAI,EAACA,gCAAAA,aAAcC,MAAM,GAAE;QACzB,OAAO;IACT;IACA,OAAO;QACLC,MAAM;QACNC,SAAS;QACT,MAAMC,WAAUC,MAAM,EAAEC,QAAQ,EAAEC,OAAO;YACvC,MAAMC,WAAW,MAAM,IAAI,CAACC,OAAO,CAACJ,QAAQC,UAAU,eACjDC;gBACHG,UAAU;;YAEZ;;;;;OAKC,GAED,MAAMC,eAAeX,aAAaY,IAAI,CAAC,CAACC;oBACtCL;uBAAAA,6BAAAA,eAAAA,SAAUM,EAAE,qBAAZN,aAAcO,QAAQ,CAACF,YAAYG,OAAO;;YAE5C,IAAIL,cAAc;gBAChBM,QAAQC,IAAI,CACV,CAAC,SAAS,EAAEP,aAAaK,OAAO,CAAC,QAAQ,EAAEL,aAAaQ,IAAI,CAAC,CAAC,CAAC;gBAEjE,IAAI;oBACF,0BAA0B;oBAC1B,OAAO;wBACLL,IAAIH,aAAaQ,IAAI;oBACvB;gBACF,EAAE,OAAOC,KAAK;oBACZH,QAAQI,KAAK,CAACD;oBACd,OAAO;gBACT;YACF;YACA,OAAO;QACT;IACF;AACF"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { ViteBuildExecutorOptions } from './schema';
|
|
3
|
-
export declare function viteBuildExecutor(options: ViteBuildExecutorOptions, context: ExecutorContext): AsyncGenerator<{
|
|
3
|
+
export declare function viteBuildExecutor(options: Record<string, any> & ViteBuildExecutorOptions, context: ExecutorContext): AsyncGenerator<{
|
|
4
4
|
success: boolean;
|
|
5
5
|
} | {
|
|
6
6
|
success: boolean;
|
|
7
7
|
outfile: string;
|
|
8
8
|
}, void, undefined>;
|
|
9
|
+
export declare function getBuildExtraArgs(options: ViteBuildExecutorOptions): Promise<{
|
|
10
|
+
buildOptions: Record<string, unknown>;
|
|
11
|
+
otherOptions: Record<string, any>;
|
|
12
|
+
}>;
|
|
9
13
|
export default viteBuildExecutor;
|
|
@@ -9,6 +9,9 @@ _export(exports, {
|
|
|
9
9
|
viteBuildExecutor: function() {
|
|
10
10
|
return viteBuildExecutor;
|
|
11
11
|
},
|
|
12
|
+
getBuildExtraArgs: function() {
|
|
13
|
+
return getBuildExtraArgs;
|
|
14
|
+
},
|
|
12
15
|
default: function() {
|
|
13
16
|
return _default;
|
|
14
17
|
}
|
|
@@ -22,25 +25,48 @@ const _path = require("path");
|
|
|
22
25
|
const _asynciterable = require("@nx/devkit/src/utils/async-iterable");
|
|
23
26
|
const _executorutils = require("../../utils/executor-utils");
|
|
24
27
|
async function* viteBuildExecutor(options, context) {
|
|
28
|
+
var _resolved_config_build, _resolved_config;
|
|
29
|
+
process.env.VITE_CJS_IGNORE_WARNING = 'true';
|
|
25
30
|
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
|
|
26
|
-
const { mergeConfig, build } = await
|
|
31
|
+
const { mergeConfig, build, loadConfigFromFile } = await (0, _executorutils.loadViteDynamicImport)();
|
|
27
32
|
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
28
33
|
(0, _executorutils.createBuildableTsConfig)(projectRoot, options, context);
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
const viteConfigPath = (0, _optionsutils.normalizeViteConfigFilePath)(context.root, projectRoot, options.configFile);
|
|
35
|
+
const root = projectRoot === '.' ? process.cwd() : (0, _path.relative)(context.cwd, (0, _devkit.joinPathFragments)(context.root, projectRoot));
|
|
36
|
+
const { buildOptions, otherOptions } = await getBuildExtraArgs(options);
|
|
37
|
+
var _otherOptions_mode;
|
|
38
|
+
const resolved = await loadConfigFromFile({
|
|
39
|
+
mode: (_otherOptions_mode = otherOptions == null ? void 0 : otherOptions.mode) != null ? _otherOptions_mode : 'production',
|
|
40
|
+
command: 'build'
|
|
41
|
+
}, viteConfigPath);
|
|
42
|
+
var _joinPathFragments;
|
|
43
|
+
const outDir = (_joinPathFragments = (0, _devkit.joinPathFragments)((0, _devkit.offsetFromRoot)(projectRoot), options.outputPath)) != null ? _joinPathFragments : resolved == null ? void 0 : (_resolved_config = resolved.config) == null ? void 0 : (_resolved_config_build = _resolved_config.build) == null ? void 0 : _resolved_config_build.outDir;
|
|
44
|
+
var _resolved_config_root;
|
|
45
|
+
const buildConfig = mergeConfig({
|
|
46
|
+
// This should not be needed as it's going to be set in vite.config.ts
|
|
47
|
+
// but leaving it here in case someone did not migrate correctly
|
|
48
|
+
root: (_resolved_config_root = resolved.config.root) != null ? _resolved_config_root : root,
|
|
49
|
+
configFile: viteConfigPath
|
|
50
|
+
}, _extends._({
|
|
51
|
+
build: _extends._({
|
|
52
|
+
outDir
|
|
53
|
+
}, buildOptions)
|
|
54
|
+
}, otherOptions));
|
|
33
55
|
if (!options.skipTypeCheck) {
|
|
56
|
+
var _options_tsConfig;
|
|
34
57
|
await (0, _executorutils.validateTypes)({
|
|
35
58
|
workspaceRoot: context.root,
|
|
36
59
|
projectRoot: projectRoot,
|
|
37
|
-
tsconfig: (0, _optionsutils.getProjectTsConfigPath)(projectRoot)
|
|
60
|
+
tsconfig: (_options_tsConfig = options.tsConfig) != null ? _options_tsConfig : (0, _optionsutils.getProjectTsConfigPath)(projectRoot)
|
|
38
61
|
});
|
|
39
62
|
}
|
|
40
63
|
const watcherOrOutput = await build(buildConfig);
|
|
41
64
|
const libraryPackageJson = (0, _path.resolve)(projectRoot, 'package.json');
|
|
42
65
|
const rootPackageJson = (0, _path.resolve)(context.root, 'package.json');
|
|
43
|
-
|
|
66
|
+
// Here, we want the outdir relative to the workspace root.
|
|
67
|
+
// So, we calculate the relative path from the workspace root to the outdir.
|
|
68
|
+
const outDirRelativeToWorkspaceRoot = outDir.replaceAll('../', '');
|
|
69
|
+
const distPackageJson = (0, _path.resolve)(outDirRelativeToWorkspaceRoot, 'package.json');
|
|
44
70
|
// Generate a package.json if option has been set.
|
|
45
71
|
if (options.generatePackageJson) {
|
|
46
72
|
if (context.projectGraph.nodes[context.projectName].type !== 'app') {
|
|
@@ -53,15 +79,15 @@ async function* viteBuildExecutor(options, context) {
|
|
|
53
79
|
isProduction: !options.includeDevDependenciesInPackageJson
|
|
54
80
|
});
|
|
55
81
|
builtPackageJson.type = 'module';
|
|
56
|
-
(0, _devkit.writeJsonFile)(`${
|
|
82
|
+
(0, _devkit.writeJsonFile)(`${outDirRelativeToWorkspaceRoot}/package.json`, builtPackageJson);
|
|
57
83
|
const packageManager = (0, _devkit.detectPackageManager)(context.root);
|
|
58
84
|
const lockFile = (0, _js.createLockFile)(builtPackageJson, context.projectGraph, packageManager);
|
|
59
|
-
(0, _fs.writeFileSync)(`${
|
|
85
|
+
(0, _fs.writeFileSync)(`${outDirRelativeToWorkspaceRoot}/${(0, _js.getLockFileName)(packageManager)}`, lockFile, {
|
|
60
86
|
encoding: 'utf-8'
|
|
61
87
|
});
|
|
62
|
-
} else if (!(0, _fs.existsSync)(distPackageJson) && (0, _fs.existsSync)(libraryPackageJson) && rootPackageJson !== libraryPackageJson) {
|
|
88
|
+
} else if (options.generatePackageJson !== false && !(0, _fs.existsSync)(distPackageJson) && (0, _fs.existsSync)(libraryPackageJson) && rootPackageJson !== libraryPackageJson) {
|
|
63
89
|
await (0, _js.copyAssets)({
|
|
64
|
-
outputPath:
|
|
90
|
+
outputPath: outDirRelativeToWorkspaceRoot,
|
|
65
91
|
assets: [
|
|
66
92
|
{
|
|
67
93
|
input: projectRoot,
|
|
@@ -86,7 +112,7 @@ async function* viteBuildExecutor(options, context) {
|
|
|
86
112
|
}
|
|
87
113
|
// result must be closed when present.
|
|
88
114
|
// see https://rollupjs.org/guide/en/#rollupwatch
|
|
89
|
-
if ('result' in event) {
|
|
115
|
+
if ('result' in event && event.result) {
|
|
90
116
|
event.result.close();
|
|
91
117
|
}
|
|
92
118
|
});
|
|
@@ -96,22 +122,65 @@ async function* viteBuildExecutor(options, context) {
|
|
|
96
122
|
var _watcherOrOutput_, _output_;
|
|
97
123
|
const output = (watcherOrOutput == null ? void 0 : watcherOrOutput['output']) || (watcherOrOutput == null ? void 0 : (_watcherOrOutput_ = watcherOrOutput[0]) == null ? void 0 : _watcherOrOutput_.output);
|
|
98
124
|
const fileName = (output == null ? void 0 : (_output_ = output[0]) == null ? void 0 : _output_.fileName) || 'main.cjs';
|
|
99
|
-
const outfile = (0, _path.resolve)(
|
|
125
|
+
const outfile = (0, _path.resolve)(outDirRelativeToWorkspaceRoot, fileName);
|
|
100
126
|
yield {
|
|
101
127
|
success: true,
|
|
102
128
|
outfile
|
|
103
129
|
};
|
|
104
130
|
}
|
|
105
131
|
}
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
132
|
+
async function getBuildExtraArgs(options) {
|
|
133
|
+
// support passing extra args to vite cli
|
|
134
|
+
const schema = await Promise.resolve().then(()=>require("./schema.json"));
|
|
135
|
+
const extraArgs = {};
|
|
136
|
+
for (const key of Object.keys(options)){
|
|
137
|
+
if (!schema.properties[key]) {
|
|
138
|
+
extraArgs[key] = options[key];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const buildOptions = {};
|
|
142
|
+
const buildSchemaKeys = [
|
|
143
|
+
'target',
|
|
144
|
+
'polyfillModulePreload',
|
|
145
|
+
'modulePreload',
|
|
146
|
+
'outDir',
|
|
147
|
+
'assetsDir',
|
|
148
|
+
'assetsInlineLimit',
|
|
149
|
+
'cssCodeSplit',
|
|
150
|
+
'cssTarget',
|
|
151
|
+
'cssMinify',
|
|
152
|
+
'sourcemap',
|
|
153
|
+
'minify',
|
|
154
|
+
'terserOptions',
|
|
155
|
+
'rollupOptions',
|
|
156
|
+
'commonjsOptions',
|
|
157
|
+
'dynamicImportVarsOptions',
|
|
158
|
+
'write',
|
|
159
|
+
'emptyOutDir',
|
|
160
|
+
'copyPublicDir',
|
|
161
|
+
'manifest',
|
|
162
|
+
'lib',
|
|
163
|
+
'ssr',
|
|
164
|
+
'ssrManifest',
|
|
165
|
+
'ssrEmitAssets',
|
|
166
|
+
'reportCompressedSize',
|
|
167
|
+
'chunkSizeWarningLimit',
|
|
168
|
+
'watch'
|
|
169
|
+
];
|
|
170
|
+
const otherOptions = {};
|
|
171
|
+
for (const key of Object.keys(extraArgs)){
|
|
172
|
+
if (buildSchemaKeys.includes(key)) {
|
|
173
|
+
buildOptions[key] = extraArgs[key];
|
|
174
|
+
} else {
|
|
175
|
+
otherOptions[key] = extraArgs[key];
|
|
176
|
+
}
|
|
113
177
|
}
|
|
114
|
-
|
|
178
|
+
var _options_watch;
|
|
179
|
+
buildOptions['watch'] = (_options_watch = options.watch) != null ? _options_watch : undefined;
|
|
180
|
+
return {
|
|
181
|
+
buildOptions,
|
|
182
|
+
otherOptions
|
|
183
|
+
};
|
|
115
184
|
}
|
|
116
185
|
const _default = viteBuildExecutor;
|
|
117
186
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/vite/src/executors/build/build.impl.ts"],"sourcesContent":["import {\n detectPackageManager,\n ExecutorContext,\n logger,\n stripIndents,\n writeJsonFile,\n} from '@nx/devkit';\nimport {\n getProjectTsConfigPath,\n getViteBuildOptions,\n getViteSharedConfig,\n} from '../../utils/options-utils';\nimport { ViteBuildExecutorOptions } from './schema';\nimport {\n copyAssets,\n createLockFile,\n createPackageJson,\n getLockFileName,\n} from '@nx/js';\nimport { existsSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { createAsyncIterable } from '@nx/devkit/src/utils/async-iterable';\nimport {\n createBuildableTsConfig,\n validateTypes,\n} from '../../utils/executor-utils';\n\nexport async function* viteBuildExecutor(\n options: ViteBuildExecutorOptions,\n context: ExecutorContext\n) {\n // Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.\n const { mergeConfig, build } = await (Function(\n 'return import(\"vite\")'\n )() as Promise<typeof import('vite')>);\n\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n\n createBuildableTsConfig(projectRoot, options, context);\n\n const normalizedOptions = normalizeOptions(options);\n\n const buildConfig = mergeConfig(\n getViteSharedConfig(normalizedOptions, false, context),\n {\n build: getViteBuildOptions(normalizedOptions, context),\n }\n );\n\n if (!options.skipTypeCheck) {\n await validateTypes({\n workspaceRoot: context.root,\n projectRoot: projectRoot,\n tsconfig: getProjectTsConfigPath(projectRoot),\n });\n }\n\n const watcherOrOutput = await build(buildConfig);\n\n const libraryPackageJson = resolve(projectRoot, 'package.json');\n const rootPackageJson = resolve(context.root, 'package.json');\n const distPackageJson = resolve(normalizedOptions.outputPath, 'package.json');\n\n // Generate a package.json if option has been set.\n if (options.generatePackageJson) {\n if (context.projectGraph.nodes[context.projectName].type !== 'app') {\n logger.warn(\n stripIndents`The project ${context.projectName} is using the 'generatePackageJson' option which is deprecated for library projects. It should only be used for applications.\n For libraries, configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).`\n );\n }\n\n const builtPackageJson = createPackageJson(\n context.projectName,\n context.projectGraph,\n {\n target: context.targetName,\n root: context.root,\n isProduction: !options.includeDevDependenciesInPackageJson, // By default we remove devDependencies since this is a production build.\n }\n );\n\n builtPackageJson.type = 'module';\n\n writeJsonFile(`${options.outputPath}/package.json`, builtPackageJson);\n const packageManager = detectPackageManager(context.root);\n\n const lockFile = createLockFile(\n builtPackageJson,\n context.projectGraph,\n packageManager\n );\n writeFileSync(\n `${options.outputPath}/${getLockFileName(packageManager)}`,\n lockFile,\n {\n encoding: 'utf-8',\n }\n );\n }\n // For buildable libs, copy package.json if it exists.\n else if (\n !existsSync(distPackageJson) &&\n existsSync(libraryPackageJson) &&\n rootPackageJson !== libraryPackageJson\n ) {\n await copyAssets(\n {\n outputPath: normalizedOptions.outputPath,\n assets: [\n {\n input: projectRoot,\n output: '.',\n glob: 'package.json',\n },\n ],\n },\n context\n );\n }\n\n if ('on' in watcherOrOutput) {\n const iterable = createAsyncIterable<{ success: boolean }>(({ next }) => {\n let success = true;\n watcherOrOutput.on('event', (event) => {\n if (event.code === 'START') {\n success = true;\n } else if (event.code === 'ERROR') {\n success = false;\n } else if (event.code === 'END') {\n next({ success });\n }\n // result must be closed when present.\n // see https://rollupjs.org/guide/en/#rollupwatch\n if ('result' in event) {\n event.result.close();\n }\n });\n });\n yield* iterable;\n } else {\n const output = watcherOrOutput?.['output'] || watcherOrOutput?.[0]?.output;\n const fileName = output?.[0]?.fileName || 'main.cjs';\n const outfile = resolve(normalizedOptions.outputPath, fileName);\n yield { success: true, outfile };\n }\n}\n\nfunction normalizeOptions(options: ViteBuildExecutorOptions) {\n const normalizedOptions = { ...options };\n\n // coerce watch to null or {} to match with Vite's watch config\n if (options.watch === false) {\n normalizedOptions.watch = null;\n } else if (options.watch === true) {\n normalizedOptions.watch = {};\n }\n\n return normalizedOptions;\n}\n\nexport default viteBuildExecutor;\n"],"names":["viteBuildExecutor","options","context","mergeConfig","build","Function","projectRoot","projectsConfigurations","projects","projectName","root","createBuildableTsConfig","normalizedOptions","normalizeOptions","buildConfig","getViteSharedConfig","getViteBuildOptions","skipTypeCheck","validateTypes","workspaceRoot","tsconfig","getProjectTsConfigPath","watcherOrOutput","libraryPackageJson","resolve","rootPackageJson","distPackageJson","outputPath","generatePackageJson","projectGraph","nodes","type","logger","warn","stripIndents","builtPackageJson","createPackageJson","target","targetName","isProduction","includeDevDependenciesInPackageJson","writeJsonFile","packageManager","detectPackageManager","lockFile","createLockFile","writeFileSync","getLockFileName","encoding","existsSync","copyAssets","assets","input","output","glob","iterable","createAsyncIterable","next","success","on","event","code","result","close","fileName","outfile","watch"],"mappings":";;;;;;;;IA2BuBA,iBAAiB;eAAjBA;;IAuIvB,OAAiC;eAAjC;;;;wBA5JO;8BAKA;oBAOA;oBACmC;sBAClB;+BACY;+BAI7B;AAEA,gBAAgBA,kBACrBC,OAAiC,EACjCC,OAAwB;IAExB,yFAAyF;IACzF,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAE,GAAG,MAAOC,SACpC;IAGF,MAAMC,cACJJ,QAAQK,sBAAsB,CAACC,QAAQ,CAACN,QAAQO,WAAW,CAAC,CAACC,IAAI;IAEnEC,IAAAA,sCAAuB,EAACL,aAAaL,SAASC;IAE9C,MAAMU,oBAAoBC,iBAAiBZ;IAE3C,MAAMa,cAAcX,YAClBY,IAAAA,iCAAmB,EAACH,mBAAmB,OAAOV,UAC9C;QACEE,OAAOY,IAAAA,iCAAmB,EAACJ,mBAAmBV;IAChD;IAGF,IAAI,CAACD,QAAQgB,aAAa,EAAE;QAC1B,MAAMC,IAAAA,4BAAa,EAAC;YAClBC,eAAejB,QAAQQ,IAAI;YAC3BJ,aAAaA;YACbc,UAAUC,IAAAA,oCAAsB,EAACf;QACnC;IACF;IAEA,MAAMgB,kBAAkB,MAAMlB,MAAMU;IAEpC,MAAMS,qBAAqBC,IAAAA,aAAO,EAAClB,aAAa;IAChD,MAAMmB,kBAAkBD,IAAAA,aAAO,EAACtB,QAAQQ,IAAI,EAAE;IAC9C,MAAMgB,kBAAkBF,IAAAA,aAAO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E;YAClE,IAAIC,UAAU;YACdpC,gBAAgBqC,EAAE,CAAC,SAAS,CAACC;gBAC3B,IAAIA,MAAMC,IAAI,KAAK,SAAS;oBAC1BH,UAAU;gBACZ,OAAO,IAAIE,MAAMC,IAAI,KAAK,SAAS;oBACjCH,UAAU;gBACZ,OAAO,IAAIE,MAAMC,IAAI,KAAK,OAAO;oBAC/BJ,KAAK;wBAAEC;oBAAQ;gBACjB;gBACA,sCAAsC;gBACtC,iDAAiD;gBACjD,IAAI,YAAYE,OAAO;oBACrBA,MAAME,MAAM,CAACC,KAAK;gBACpB;YACF;QACF;QACA,OAAOR;IACT,OAAO;YACyCjC,mBAC7B+B;QADjB,MAAMA,SAAS/B,CAAAA,mCAAAA,eAAiB,CAAC,SAAS,MAAIA,oCAAAA,oBAAAA,eAAiB,CAAC,EAAE,qBAApBA,kBAAsB+B,MAAM;QAC1E,MAAMW,WAAWX,CAAAA,2BAAAA,WAAAA,MAAQ,CAAC,EAAE,qBAAXA,SAAaW,QAAQ,KAAI;QAC1C,MAAMC,UAAUzC,IAAAA,aAAO,EAACZ,kBAAkBe,UAAU,EAAEqC;QACtD,MAAM;YAAEN,SAAS;YAAMO;QAAQ;IACjC;AACF;AAEA,SAASpD,iBAAiBZ,OAAiC;IACzD,MAAMW,oBAAoB,eAAKX;IAE/B,+DAA+D;IAC/D,IAAIA,QAAQiE,KAAK,KAAK,OAAO;QAC3BtD,kBAAkBsD,KAAK,GAAG;IAC5B,OAAO,IAAIjE,QAAQiE,KAAK,KAAK,MAAM;QACjCtD,kBAAkBsD,KAAK,GAAG,CAAC;IAC7B;IAEA,OAAOtD;AACT;MAEA,WAAeZ"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/executors/build/build.impl.ts"],"sourcesContent":["import {\n detectPackageManager,\n ExecutorContext,\n joinPathFragments,\n logger,\n offsetFromRoot,\n stripIndents,\n writeJsonFile,\n} from '@nx/devkit';\nimport {\n getProjectTsConfigPath,\n normalizeViteConfigFilePath,\n} from '../../utils/options-utils';\nimport { ViteBuildExecutorOptions } from './schema';\nimport {\n copyAssets,\n createLockFile,\n createPackageJson,\n getLockFileName,\n} from '@nx/js';\nimport { existsSync, writeFileSync } from 'fs';\nimport { relative, resolve } from 'path';\nimport { createAsyncIterable } from '@nx/devkit/src/utils/async-iterable';\nimport {\n createBuildableTsConfig,\n loadViteDynamicImport,\n validateTypes,\n} from '../../utils/executor-utils';\n\nexport async function* viteBuildExecutor(\n options: Record<string, any> & ViteBuildExecutorOptions,\n context: ExecutorContext\n) {\n process.env.VITE_CJS_IGNORE_WARNING = 'true';\n // Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.\n const { mergeConfig, build, loadConfigFromFile } =\n await loadViteDynamicImport();\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n createBuildableTsConfig(projectRoot, options, context);\n\n const viteConfigPath = normalizeViteConfigFilePath(\n context.root,\n projectRoot,\n options.configFile\n );\n const root =\n projectRoot === '.'\n ? process.cwd()\n : relative(context.cwd, joinPathFragments(context.root, projectRoot));\n\n const { buildOptions, otherOptions } = await getBuildExtraArgs(options);\n\n const resolved = await loadConfigFromFile(\n {\n mode: otherOptions?.mode ?? 'production',\n command: 'build',\n },\n viteConfigPath\n );\n\n const outDir =\n joinPathFragments(offsetFromRoot(projectRoot), options.outputPath) ??\n resolved?.config?.build?.outDir;\n\n const buildConfig = mergeConfig(\n {\n // This should not be needed as it's going to be set in vite.config.ts\n // but leaving it here in case someone did not migrate correctly\n root: resolved.config.root ?? root,\n configFile: viteConfigPath,\n },\n {\n build: {\n outDir,\n ...buildOptions,\n },\n ...otherOptions,\n }\n );\n\n if (!options.skipTypeCheck) {\n await validateTypes({\n workspaceRoot: context.root,\n projectRoot: projectRoot,\n tsconfig: options.tsConfig ?? getProjectTsConfigPath(projectRoot),\n });\n }\n\n const watcherOrOutput = await build(buildConfig);\n\n const libraryPackageJson = resolve(projectRoot, 'package.json');\n const rootPackageJson = resolve(context.root, 'package.json');\n\n // Here, we want the outdir relative to the workspace root.\n // So, we calculate the relative path from the workspace root to the outdir.\n const outDirRelativeToWorkspaceRoot = outDir.replaceAll('../', '');\n const distPackageJson = resolve(\n outDirRelativeToWorkspaceRoot,\n 'package.json'\n );\n\n // Generate a package.json if option has been set.\n if (options.generatePackageJson) {\n if (context.projectGraph.nodes[context.projectName].type !== 'app') {\n logger.warn(\n stripIndents`The project ${context.projectName} is using the 'generatePackageJson' option which is deprecated for library projects. It should only be used for applications.\n For libraries, configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).`\n );\n }\n\n const builtPackageJson = createPackageJson(\n context.projectName,\n context.projectGraph,\n {\n target: context.targetName,\n root: context.root,\n isProduction: !options.includeDevDependenciesInPackageJson, // By default we remove devDependencies since this is a production build.\n }\n );\n\n builtPackageJson.type = 'module';\n\n writeJsonFile(\n `${outDirRelativeToWorkspaceRoot}/package.json`,\n builtPackageJson\n );\n const packageManager = detectPackageManager(context.root);\n\n const lockFile = createLockFile(\n builtPackageJson,\n context.projectGraph,\n packageManager\n );\n writeFileSync(\n `${outDirRelativeToWorkspaceRoot}/${getLockFileName(packageManager)}`,\n lockFile,\n {\n encoding: 'utf-8',\n }\n );\n }\n // For buildable libs, copy package.json if it exists.\n else if (\n options.generatePackageJson !== false &&\n !existsSync(distPackageJson) &&\n existsSync(libraryPackageJson) &&\n rootPackageJson !== libraryPackageJson\n ) {\n await copyAssets(\n {\n outputPath: outDirRelativeToWorkspaceRoot,\n assets: [\n {\n input: projectRoot,\n output: '.',\n glob: 'package.json',\n },\n ],\n },\n context\n );\n }\n\n if ('on' in watcherOrOutput) {\n const iterable = createAsyncIterable<{ success: boolean }>(({ next }) => {\n let success = true;\n watcherOrOutput.on('event', (event) => {\n if (event.code === 'START') {\n success = true;\n } else if (event.code === 'ERROR') {\n success = false;\n } else if (event.code === 'END') {\n next({ success });\n }\n // result must be closed when present.\n // see https://rollupjs.org/guide/en/#rollupwatch\n if ('result' in event && event.result) {\n event.result.close();\n }\n });\n });\n yield* iterable;\n } else {\n const output = watcherOrOutput?.['output'] || watcherOrOutput?.[0]?.output;\n const fileName = output?.[0]?.fileName || 'main.cjs';\n const outfile = resolve(outDirRelativeToWorkspaceRoot, fileName);\n yield { success: true, outfile };\n }\n}\n\nexport async function getBuildExtraArgs(\n options: ViteBuildExecutorOptions\n): Promise<{\n // vite BuildOptions\n buildOptions: Record<string, unknown>;\n otherOptions: Record<string, any>;\n}> {\n // support passing extra args to vite cli\n const schema = await import('./schema.json');\n const extraArgs = {};\n for (const key of Object.keys(options)) {\n if (!schema.properties[key]) {\n extraArgs[key] = options[key];\n }\n }\n\n const buildOptions = {};\n const buildSchemaKeys = [\n 'target',\n 'polyfillModulePreload',\n 'modulePreload',\n 'outDir',\n 'assetsDir',\n 'assetsInlineLimit',\n 'cssCodeSplit',\n 'cssTarget',\n 'cssMinify',\n 'sourcemap',\n 'minify',\n 'terserOptions',\n 'rollupOptions',\n 'commonjsOptions',\n 'dynamicImportVarsOptions',\n 'write',\n 'emptyOutDir',\n 'copyPublicDir',\n 'manifest',\n 'lib',\n 'ssr',\n 'ssrManifest',\n 'ssrEmitAssets',\n 'reportCompressedSize',\n 'chunkSizeWarningLimit',\n 'watch',\n ];\n const otherOptions = {};\n for (const key of Object.keys(extraArgs)) {\n if (buildSchemaKeys.includes(key)) {\n buildOptions[key] = extraArgs[key];\n } else {\n otherOptions[key] = extraArgs[key];\n }\n }\n\n buildOptions['watch'] = options.watch ?? undefined;\n\n return {\n buildOptions,\n otherOptions,\n };\n}\n\nexport default viteBuildExecutor;\n"],"names":["viteBuildExecutor","getBuildExtraArgs","options","context","resolved","process","env","VITE_CJS_IGNORE_WARNING","mergeConfig","build","loadConfigFromFile","loadViteDynamicImport","projectRoot","projectsConfigurations","projects","projectName","root","createBuildableTsConfig","viteConfigPath","normalizeViteConfigFilePath","configFile","cwd","relative","joinPathFragments","buildOptions","otherOptions","mode","command","outDir","offsetFromRoot","outputPath","config","buildConfig","skipTypeCheck","validateTypes","workspaceRoot","tsconfig","tsConfig","getProjectTsConfigPath","watcherOrOutput","libraryPackageJson","resolve","rootPackageJson","outDirRelativeToWorkspaceRoot","replaceAll","distPackageJson","generatePackageJson","projectGraph","nodes","type","logger","warn","stripIndents","builtPackageJson","createPackageJson","target","targetName","isProduction","includeDevDependenciesInPackageJson","writeJsonFile","packageManager","detectPackageManager","lockFile","createLockFile","writeFileSync","getLockFileName","encoding","existsSync","copyAssets","assets","input","output","glob","iterable","createAsyncIterable","next","success","on","event","code","result","close","fileName","outfile","schema","extraArgs","key","Object","keys","properties","buildSchemaKeys","includes","watch","undefined"],"mappings":";;;;;;;;IA6BuBA,iBAAiB;eAAjBA;;IAkKDC,iBAAiB;eAAjBA;;IA8DtB,OAAiC;eAAjC;;;;wBArPO;8BAIA;oBAOA;oBACmC;sBACR;+BACE;+BAK7B;AAEA,gBAAgBD,kBACrBE,OAAuD,EACvDC,OAAwB;QAgCtBC,wBAAAA;IA9BFC,QAAQC,GAAG,CAACC,uBAAuB,GAAG;IACtC,yFAAyF;IACzF,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAEC,kBAAkB,EAAE,GAC9C,MAAMC,IAAAA,oCAAqB;IAC7B,MAAMC,cACJT,QAAQU,sBAAsB,CAACC,QAAQ,CAACX,QAAQY,WAAW,CAAC,CAACC,IAAI;IACnEC,IAAAA,sCAAuB,EAACL,aAAaV,SAASC;IAE9C,MAAMe,iBAAiBC,IAAAA,yCAA2B,EAChDhB,QAAQa,IAAI,EACZJ,aACAV,QAAQkB,UAAU;IAEpB,MAAMJ,OACJJ,gBAAgB,MACZP,QAAQgB,GAAG,KACXC,IAAAA,cAAQ,EAACnB,QAAQkB,GAAG,EAAEE,IAAAA,yBAAiB,EAACpB,QAAQa,IAAI,EAAEJ;IAE5D,MAAM,EAAEY,YAAY,EAAEC,YAAY,EAAE,GAAG,MAAMxB,kBAAkBC;QAIrDuB;IAFV,MAAMrB,WAAW,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