@bleedingdev/modern-js-builder 3.8.2-ultramodern.9 → 3.8.3-ultramodern.2
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/dist/cjs/createBuilder.js +1 -4
- package/dist/cjs/plugins/rscConfig.js +0 -138
- package/dist/cjs/shared/parseCommonConfig.js +6 -14
- package/dist/esm/createBuilder.mjs +1 -4
- package/dist/esm/plugins/rscConfig.mjs +1 -136
- package/dist/esm/shared/parseCommonConfig.mjs +6 -14
- package/dist/esm-node/createBuilder.mjs +1 -4
- package/dist/esm-node/plugins/rscConfig.mjs +1 -136
- package/dist/esm-node/shared/parseCommonConfig.mjs +6 -14
- package/dist/types/plugins/rscConfig.d.ts +0 -32
- package/dist/types/shared/parseCommonConfig.d.ts +0 -2
- package/dist/types/types.d.ts +1 -12
- package/package.json +6 -7
- package/dist/cjs/plugins/environmentBuildCache.js +0 -89
- package/dist/cjs/plugins/rsdoctor.js +0 -68
- package/dist/cjs/plugins/rspack21.js +0 -61
- package/dist/cjs/rsdoctorConfig.js +0 -18
- package/dist/cjs/shared/tsgo.js +0 -212
- package/dist/esm/plugins/environmentBuildCache.mjs +0 -38
- package/dist/esm/plugins/rsdoctor.mjs +0 -30
- package/dist/esm/plugins/rspack21.mjs +0 -23
- package/dist/esm/rsdoctorConfig.mjs +0 -0
- package/dist/esm/shared/tsgo.mjs +0 -160
- package/dist/esm-node/plugins/environmentBuildCache.mjs +0 -39
- package/dist/esm-node/plugins/rsdoctor.mjs +0 -31
- package/dist/esm-node/plugins/rspack21.mjs +0 -24
- package/dist/esm-node/rsdoctorConfig.mjs +0 -1
- package/dist/esm-node/shared/tsgo.mjs +0 -161
- package/dist/types/plugins/environmentBuildCache.d.ts +0 -3
- package/dist/types/plugins/rsdoctor.d.ts +0 -3
- package/dist/types/plugins/rspack21.d.ts +0 -4
- package/dist/types/rsdoctorConfig.d.ts +0 -12
- package/dist/types/shared/tsgo.d.ts +0 -12
package/dist/cjs/shared/tsgo.js
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
-
return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
|
-
}();
|
|
5
|
-
var __webpack_require__ = {};
|
|
6
|
-
(()=>{
|
|
7
|
-
__webpack_require__.n = (module)=>{
|
|
8
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
9
|
-
__webpack_require__.d(getter, {
|
|
10
|
-
a: getter
|
|
11
|
-
});
|
|
12
|
-
return getter;
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
(()=>{
|
|
16
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
17
|
-
var define = (defs, kind)=>{
|
|
18
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
[kind]: defs[key]
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
define(getters, "get");
|
|
24
|
-
define(values, "value");
|
|
25
|
-
};
|
|
26
|
-
})();
|
|
27
|
-
(()=>{
|
|
28
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
29
|
-
})();
|
|
30
|
-
(()=>{
|
|
31
|
-
__webpack_require__.r = (exports1)=>{
|
|
32
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
33
|
-
value: 'Module'
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
36
|
-
value: true
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
var __webpack_exports__ = {};
|
|
41
|
-
__webpack_require__.r(__webpack_exports__);
|
|
42
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
43
|
-
withTsgoDefaults: ()=>withTsgoDefaults
|
|
44
|
-
});
|
|
45
|
-
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
46
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
47
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
48
|
-
const external_node_module_namespaceObject = require("node:module");
|
|
49
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
50
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
51
|
-
const utils_namespaceObject = require("@modern-js/utils");
|
|
52
|
-
const builderRequire = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
53
|
-
const STABLE_TSGO_PACKAGE = "typescript/package.json";
|
|
54
|
-
const NATIVE_PREVIEW_TSGO_PACKAGE = "@typescript/native-preview/package.json";
|
|
55
|
-
const TSGO_CHECKER_DIR = external_node_path_default().join('.modern-js', 'tsgo');
|
|
56
|
-
const tryResolve = (request, rootPath)=>{
|
|
57
|
-
try {
|
|
58
|
-
return builderRequire.resolve(request, {
|
|
59
|
-
paths: [
|
|
60
|
-
rootPath
|
|
61
|
-
]
|
|
62
|
-
});
|
|
63
|
-
} catch {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const readPackageMajorVersion = (packageJsonPath)=>{
|
|
68
|
-
try {
|
|
69
|
-
const packageJson = JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, 'utf8'));
|
|
70
|
-
const major = Number.parseInt(String(packageJson.version).split('.')[0], 10);
|
|
71
|
-
return Number.isFinite(major) ? major : void 0;
|
|
72
|
-
} catch {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const resolveTsgoPackagePath = (rootPath)=>{
|
|
77
|
-
const stableTypeScriptPath = tryResolve(STABLE_TSGO_PACKAGE, rootPath);
|
|
78
|
-
if (stableTypeScriptPath && (readPackageMajorVersion(stableTypeScriptPath) ?? 0) >= 7) return stableTypeScriptPath;
|
|
79
|
-
return tryResolve(NATIVE_PREVIEW_TSGO_PACKAGE, rootPath) ?? builderRequire.resolve(NATIVE_PREVIEW_TSGO_PACKAGE);
|
|
80
|
-
};
|
|
81
|
-
const toPosixPath = (input)=>input.replaceAll(external_node_path_default().sep, '/');
|
|
82
|
-
const asTsConfigPath = (request)=>{
|
|
83
|
-
if (external_node_path_default().extname(request)) return [
|
|
84
|
-
request
|
|
85
|
-
];
|
|
86
|
-
return [
|
|
87
|
-
request,
|
|
88
|
-
`${request}.json`
|
|
89
|
-
];
|
|
90
|
-
};
|
|
91
|
-
const resolveExtends = (request, configDirectory)=>{
|
|
92
|
-
const configRequire = (0, external_node_module_namespaceObject.createRequire)(external_node_path_default().join(configDirectory, 'tsconfig.json'));
|
|
93
|
-
for (const candidate of asTsConfigPath(request)){
|
|
94
|
-
if (candidate.startsWith('.') || external_node_path_default().isAbsolute(candidate)) {
|
|
95
|
-
const resolved = external_node_path_default().resolve(configDirectory, candidate);
|
|
96
|
-
if (external_node_fs_default().existsSync(resolved)) return resolved;
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
return configRequire.resolve(candidate);
|
|
101
|
-
} catch {}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const readTsConfig = (configFile, visited = new Set())=>{
|
|
105
|
-
if (visited.has(configFile) || !external_node_fs_default().existsSync(configFile)) return {};
|
|
106
|
-
visited.add(configFile);
|
|
107
|
-
const config = utils_namespaceObject.json5.parse(external_node_fs_default().readFileSync(configFile, 'utf8'));
|
|
108
|
-
const configDirectory = external_node_path_default().dirname(configFile);
|
|
109
|
-
const extendsList = Array.isArray(config.extends) ? config.extends : config.extends ? [
|
|
110
|
-
config.extends
|
|
111
|
-
] : [];
|
|
112
|
-
const baseConfig = extendsList.reduce((merged, request)=>{
|
|
113
|
-
const resolved = resolveExtends(request, configDirectory);
|
|
114
|
-
if (!resolved) return merged;
|
|
115
|
-
const parentConfig = readTsConfig(resolved, visited);
|
|
116
|
-
return {
|
|
117
|
-
...merged,
|
|
118
|
-
compilerOptions: {
|
|
119
|
-
...merged.compilerOptions ?? {},
|
|
120
|
-
...parentConfig.compilerOptions ?? {}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}, {});
|
|
124
|
-
return {
|
|
125
|
-
...baseConfig,
|
|
126
|
-
compilerOptions: {
|
|
127
|
-
...baseConfig.compilerOptions ?? {},
|
|
128
|
-
...config.compilerOptions ?? {}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
const toRelativeConfigPath = (fromDirectory, target)=>{
|
|
133
|
-
const relative = toPosixPath(external_node_path_default().relative(fromDirectory, target));
|
|
134
|
-
if (relative.startsWith('.')) return relative;
|
|
135
|
-
return `./${relative}`;
|
|
136
|
-
};
|
|
137
|
-
const writeFileIfChanged = (file, content)=>{
|
|
138
|
-
if (external_node_fs_default().existsSync(file) && external_node_fs_default().readFileSync(file, 'utf8') === content) return;
|
|
139
|
-
external_node_fs_default().writeFileSync(file, content);
|
|
140
|
-
};
|
|
141
|
-
const createTsgoCheckerConfig = (configFile)=>{
|
|
142
|
-
const configDirectory = external_node_path_default().dirname(configFile);
|
|
143
|
-
const checkerConfigDirectory = external_node_path_default().join(configDirectory, TSGO_CHECKER_DIR);
|
|
144
|
-
const hash = (0, external_node_crypto_namespaceObject.createHash)('sha1').update(configFile).digest('hex').slice(0, 10);
|
|
145
|
-
const checkerConfigFile = external_node_path_default().join(checkerConfigDirectory, `tsconfig.${hash}.json`);
|
|
146
|
-
const tsConfig = readTsConfig(configFile);
|
|
147
|
-
const compilerOptions = {
|
|
148
|
-
baseUrl: null
|
|
149
|
-
};
|
|
150
|
-
const moduleResolution = String(tsConfig.compilerOptions?.moduleResolution).toLowerCase();
|
|
151
|
-
if ([
|
|
152
|
-
'node',
|
|
153
|
-
'node10'
|
|
154
|
-
].includes(moduleResolution)) compilerOptions.moduleResolution = null;
|
|
155
|
-
const checkerConfig = {
|
|
156
|
-
extends: toRelativeConfigPath(checkerConfigDirectory, configFile),
|
|
157
|
-
compilerOptions
|
|
158
|
-
};
|
|
159
|
-
external_node_fs_default().mkdirSync(checkerConfigDirectory, {
|
|
160
|
-
recursive: true
|
|
161
|
-
});
|
|
162
|
-
writeFileIfChanged(checkerConfigFile, `${JSON.stringify(checkerConfig, null, 2)}\n`);
|
|
163
|
-
return checkerConfigFile;
|
|
164
|
-
};
|
|
165
|
-
const normalizeTsgoConfig = (config, rootPath)=>{
|
|
166
|
-
const { typescript } = config;
|
|
167
|
-
if (typescript?.tsgo === false) return config;
|
|
168
|
-
const compilerOptions = {
|
|
169
|
-
...typescript?.configOverwrite?.compilerOptions ?? {},
|
|
170
|
-
baseUrl: null
|
|
171
|
-
};
|
|
172
|
-
if ([
|
|
173
|
-
'node',
|
|
174
|
-
'node10'
|
|
175
|
-
].includes(String(compilerOptions.moduleResolution).toLowerCase())) compilerOptions.moduleResolution = null;
|
|
176
|
-
config.typescript = {
|
|
177
|
-
...typescript,
|
|
178
|
-
configOverwrite: {
|
|
179
|
-
...typescript?.configOverwrite ?? {},
|
|
180
|
-
compilerOptions
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
if (typescript?.configFile) config.typescript.configFile = createTsgoCheckerConfig(external_node_path_default().resolve(rootPath, typescript.configFile));
|
|
184
|
-
return config;
|
|
185
|
-
};
|
|
186
|
-
const withTsgoDefaults = (userOptions, rootPath)=>{
|
|
187
|
-
const tsgoPath = resolveTsgoPackagePath(rootPath);
|
|
188
|
-
const userChain = userOptions ? Array.isArray(userOptions) ? userOptions : [
|
|
189
|
-
userOptions
|
|
190
|
-
] : [];
|
|
191
|
-
return [
|
|
192
|
-
{
|
|
193
|
-
typescript: {
|
|
194
|
-
tsgo: true,
|
|
195
|
-
typescriptPath: tsgoPath
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
...userChain,
|
|
199
|
-
(config)=>{
|
|
200
|
-
const { typescript } = config;
|
|
201
|
-
if (typescript?.tsgo === false && typescript.typescriptPath === tsgoPath) typescript.typescriptPath = tryResolve("typescript", rootPath);
|
|
202
|
-
return normalizeTsgoConfig(config, rootPath);
|
|
203
|
-
}
|
|
204
|
-
];
|
|
205
|
-
};
|
|
206
|
-
exports.withTsgoDefaults = __webpack_exports__.withTsgoDefaults;
|
|
207
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
208
|
-
"withTsgoDefaults"
|
|
209
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
210
|
-
Object.defineProperty(exports, '__esModule', {
|
|
211
|
-
value: true
|
|
212
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import node_path from "node:path";
|
|
2
|
-
const DEFAULT_RSPACK_CACHE_DIRECTORY = 'node_modules/.cache/rspack';
|
|
3
|
-
function sanitizeCachePathSegment(value) {
|
|
4
|
-
return value.replace(/[^a-zA-Z0-9._-]+/gu, '_');
|
|
5
|
-
}
|
|
6
|
-
function pathEndsWithSegment(filePath, segment) {
|
|
7
|
-
const normalized = filePath.replace(/[\\/]+$/u, '');
|
|
8
|
-
return normalized.split(/[\\/]+/u).at(-1) === segment;
|
|
9
|
-
}
|
|
10
|
-
function isolateEnvironmentBuildCacheDirectory(cacheDirectory, environmentName) {
|
|
11
|
-
const segment = sanitizeCachePathSegment(environmentName);
|
|
12
|
-
const baseDirectory = cacheDirectory || DEFAULT_RSPACK_CACHE_DIRECTORY;
|
|
13
|
-
return pathEndsWithSegment(baseDirectory, segment) ? baseDirectory : node_path.join(baseDirectory, segment);
|
|
14
|
-
}
|
|
15
|
-
const pluginEnvironmentBuildCacheIsolation = ()=>({
|
|
16
|
-
name: 'modern-js:environment-build-cache-isolation',
|
|
17
|
-
setup (api) {
|
|
18
|
-
api.modifyEnvironmentConfig({
|
|
19
|
-
order: 'post',
|
|
20
|
-
handler: (config, { name })=>{
|
|
21
|
-
const buildCache = config.performance.buildCache;
|
|
22
|
-
if (false === buildCache || void 0 === buildCache) return;
|
|
23
|
-
const buildCacheConfig = true === buildCache ? {} : buildCache;
|
|
24
|
-
return {
|
|
25
|
-
...config,
|
|
26
|
-
performance: {
|
|
27
|
-
...config.performance,
|
|
28
|
-
buildCache: {
|
|
29
|
-
...buildCacheConfig,
|
|
30
|
-
cacheDirectory: isolateEnvironmentBuildCacheDirectory(buildCacheConfig.cacheDirectory, name)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
export { isolateEnvironmentBuildCacheDirectory, pluginEnvironmentBuildCacheIsolation };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const isRsdoctorEnabled = (config)=>{
|
|
2
|
-
if (void 0 === config) return false;
|
|
3
|
-
if ('boolean' == typeof config) return config;
|
|
4
|
-
if ('boolean' == typeof config?.enabled) return config.enabled;
|
|
5
|
-
return true;
|
|
6
|
-
};
|
|
7
|
-
const getRsdoctorPluginOptions = (config)=>{
|
|
8
|
-
if (config && 'object' == typeof config) return {
|
|
9
|
-
disableClientServer: config.disableClientServer ?? true
|
|
10
|
-
};
|
|
11
|
-
return {
|
|
12
|
-
disableClientServer: true
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
const pluginRsdoctor = (config)=>{
|
|
16
|
-
if (!isRsdoctorEnabled(config)) return null;
|
|
17
|
-
const pluginOptions = getRsdoctorPluginOptions(config);
|
|
18
|
-
return {
|
|
19
|
-
name: 'builder:rsdoctor',
|
|
20
|
-
setup (api) {
|
|
21
|
-
api.modifyBundlerChain(async (chain)=>{
|
|
22
|
-
const { RsdoctorRspackPlugin } = await import("@rsdoctor/rspack-plugin");
|
|
23
|
-
chain.plugin('rsdoctor').use(RsdoctorRspackPlugin, [
|
|
24
|
-
pluginOptions
|
|
25
|
-
]);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export { pluginRsdoctor };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const PERSISTENT_CACHE_MAX_AGE = 604800;
|
|
2
|
-
const PERSISTENT_CACHE_MAX_VERSIONS = 3;
|
|
3
|
-
const pluginRspack21 = ({ sourceImport } = {})=>({
|
|
4
|
-
name: 'modern-js:rspack-2-1-defaults',
|
|
5
|
-
setup (api) {
|
|
6
|
-
api.modifyRspackConfig((config)=>{
|
|
7
|
-
config.module ??= {};
|
|
8
|
-
config.module.parser ??= {};
|
|
9
|
-
config.module.parser.javascript ??= {};
|
|
10
|
-
config.module.parser.javascript.createRequire ??= true;
|
|
11
|
-
if ('object' == typeof config.cache && null !== config.cache && 'persistent' === config.cache.type) {
|
|
12
|
-
config.cache.maxAge ??= PERSISTENT_CACHE_MAX_AGE;
|
|
13
|
-
config.cache.maxVersions ??= PERSISTENT_CACHE_MAX_VERSIONS;
|
|
14
|
-
}
|
|
15
|
-
if (void 0 !== sourceImport) {
|
|
16
|
-
config.experiments ??= {};
|
|
17
|
-
config.experiments.sourceImport = sourceImport;
|
|
18
|
-
}
|
|
19
|
-
return config;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
export { pluginRspack21 };
|
|
File without changes
|
package/dist/esm/shared/tsgo.mjs
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import node_fs from "node:fs";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
import node_path from "node:path";
|
|
5
|
-
import { json5 } from "@modern-js/utils";
|
|
6
|
-
const builderRequire = createRequire(import.meta.url);
|
|
7
|
-
const STABLE_TSGO_PACKAGE = "typescript/package.json";
|
|
8
|
-
const NATIVE_PREVIEW_TSGO_PACKAGE = "@typescript/native-preview/package.json";
|
|
9
|
-
const TSGO_CHECKER_DIR = node_path.join('.modern-js', 'tsgo');
|
|
10
|
-
const tryResolve = (request, rootPath)=>{
|
|
11
|
-
try {
|
|
12
|
-
return builderRequire.resolve(request, {
|
|
13
|
-
paths: [
|
|
14
|
-
rootPath
|
|
15
|
-
]
|
|
16
|
-
});
|
|
17
|
-
} catch {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const readPackageMajorVersion = (packageJsonPath)=>{
|
|
22
|
-
try {
|
|
23
|
-
const packageJson = JSON.parse(node_fs.readFileSync(packageJsonPath, 'utf8'));
|
|
24
|
-
const major = Number.parseInt(String(packageJson.version).split('.')[0], 10);
|
|
25
|
-
return Number.isFinite(major) ? major : void 0;
|
|
26
|
-
} catch {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const resolveTsgoPackagePath = (rootPath)=>{
|
|
31
|
-
const stableTypeScriptPath = tryResolve(STABLE_TSGO_PACKAGE, rootPath);
|
|
32
|
-
if (stableTypeScriptPath && (readPackageMajorVersion(stableTypeScriptPath) ?? 0) >= 7) return stableTypeScriptPath;
|
|
33
|
-
return tryResolve(NATIVE_PREVIEW_TSGO_PACKAGE, rootPath) ?? builderRequire.resolve(NATIVE_PREVIEW_TSGO_PACKAGE);
|
|
34
|
-
};
|
|
35
|
-
const toPosixPath = (input)=>input.replaceAll(node_path.sep, '/');
|
|
36
|
-
const asTsConfigPath = (request)=>{
|
|
37
|
-
if (node_path.extname(request)) return [
|
|
38
|
-
request
|
|
39
|
-
];
|
|
40
|
-
return [
|
|
41
|
-
request,
|
|
42
|
-
`${request}.json`
|
|
43
|
-
];
|
|
44
|
-
};
|
|
45
|
-
const resolveExtends = (request, configDirectory)=>{
|
|
46
|
-
const configRequire = createRequire(node_path.join(configDirectory, 'tsconfig.json'));
|
|
47
|
-
for (const candidate of asTsConfigPath(request)){
|
|
48
|
-
if (candidate.startsWith('.') || node_path.isAbsolute(candidate)) {
|
|
49
|
-
const resolved = node_path.resolve(configDirectory, candidate);
|
|
50
|
-
if (node_fs.existsSync(resolved)) return resolved;
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
return configRequire.resolve(candidate);
|
|
55
|
-
} catch {}
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const readTsConfig = (configFile, visited = new Set())=>{
|
|
59
|
-
if (visited.has(configFile) || !node_fs.existsSync(configFile)) return {};
|
|
60
|
-
visited.add(configFile);
|
|
61
|
-
const config = json5.parse(node_fs.readFileSync(configFile, 'utf8'));
|
|
62
|
-
const configDirectory = node_path.dirname(configFile);
|
|
63
|
-
const extendsList = Array.isArray(config.extends) ? config.extends : config.extends ? [
|
|
64
|
-
config.extends
|
|
65
|
-
] : [];
|
|
66
|
-
const baseConfig = extendsList.reduce((merged, request)=>{
|
|
67
|
-
const resolved = resolveExtends(request, configDirectory);
|
|
68
|
-
if (!resolved) return merged;
|
|
69
|
-
const parentConfig = readTsConfig(resolved, visited);
|
|
70
|
-
return {
|
|
71
|
-
...merged,
|
|
72
|
-
compilerOptions: {
|
|
73
|
-
...merged.compilerOptions ?? {},
|
|
74
|
-
...parentConfig.compilerOptions ?? {}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}, {});
|
|
78
|
-
return {
|
|
79
|
-
...baseConfig,
|
|
80
|
-
compilerOptions: {
|
|
81
|
-
...baseConfig.compilerOptions ?? {},
|
|
82
|
-
...config.compilerOptions ?? {}
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
const toRelativeConfigPath = (fromDirectory, target)=>{
|
|
87
|
-
const relative = toPosixPath(node_path.relative(fromDirectory, target));
|
|
88
|
-
if (relative.startsWith('.')) return relative;
|
|
89
|
-
return `./${relative}`;
|
|
90
|
-
};
|
|
91
|
-
const writeFileIfChanged = (file, content)=>{
|
|
92
|
-
if (node_fs.existsSync(file) && node_fs.readFileSync(file, 'utf8') === content) return;
|
|
93
|
-
node_fs.writeFileSync(file, content);
|
|
94
|
-
};
|
|
95
|
-
const createTsgoCheckerConfig = (configFile)=>{
|
|
96
|
-
const configDirectory = node_path.dirname(configFile);
|
|
97
|
-
const checkerConfigDirectory = node_path.join(configDirectory, TSGO_CHECKER_DIR);
|
|
98
|
-
const hash = createHash('sha1').update(configFile).digest('hex').slice(0, 10);
|
|
99
|
-
const checkerConfigFile = node_path.join(checkerConfigDirectory, `tsconfig.${hash}.json`);
|
|
100
|
-
const tsConfig = readTsConfig(configFile);
|
|
101
|
-
const compilerOptions = {
|
|
102
|
-
baseUrl: null
|
|
103
|
-
};
|
|
104
|
-
const moduleResolution = String(tsConfig.compilerOptions?.moduleResolution).toLowerCase();
|
|
105
|
-
if ([
|
|
106
|
-
'node',
|
|
107
|
-
'node10'
|
|
108
|
-
].includes(moduleResolution)) compilerOptions.moduleResolution = null;
|
|
109
|
-
const checkerConfig = {
|
|
110
|
-
extends: toRelativeConfigPath(checkerConfigDirectory, configFile),
|
|
111
|
-
compilerOptions
|
|
112
|
-
};
|
|
113
|
-
node_fs.mkdirSync(checkerConfigDirectory, {
|
|
114
|
-
recursive: true
|
|
115
|
-
});
|
|
116
|
-
writeFileIfChanged(checkerConfigFile, `${JSON.stringify(checkerConfig, null, 2)}\n`);
|
|
117
|
-
return checkerConfigFile;
|
|
118
|
-
};
|
|
119
|
-
const normalizeTsgoConfig = (config, rootPath)=>{
|
|
120
|
-
const { typescript } = config;
|
|
121
|
-
if (typescript?.tsgo === false) return config;
|
|
122
|
-
const compilerOptions = {
|
|
123
|
-
...typescript?.configOverwrite?.compilerOptions ?? {},
|
|
124
|
-
baseUrl: null
|
|
125
|
-
};
|
|
126
|
-
if ([
|
|
127
|
-
'node',
|
|
128
|
-
'node10'
|
|
129
|
-
].includes(String(compilerOptions.moduleResolution).toLowerCase())) compilerOptions.moduleResolution = null;
|
|
130
|
-
config.typescript = {
|
|
131
|
-
...typescript,
|
|
132
|
-
configOverwrite: {
|
|
133
|
-
...typescript?.configOverwrite ?? {},
|
|
134
|
-
compilerOptions
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
if (typescript?.configFile) config.typescript.configFile = createTsgoCheckerConfig(node_path.resolve(rootPath, typescript.configFile));
|
|
138
|
-
return config;
|
|
139
|
-
};
|
|
140
|
-
const withTsgoDefaults = (userOptions, rootPath)=>{
|
|
141
|
-
const tsgoPath = resolveTsgoPackagePath(rootPath);
|
|
142
|
-
const userChain = userOptions ? Array.isArray(userOptions) ? userOptions : [
|
|
143
|
-
userOptions
|
|
144
|
-
] : [];
|
|
145
|
-
return [
|
|
146
|
-
{
|
|
147
|
-
typescript: {
|
|
148
|
-
tsgo: true,
|
|
149
|
-
typescriptPath: tsgoPath
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
...userChain,
|
|
153
|
-
(config)=>{
|
|
154
|
-
const { typescript } = config;
|
|
155
|
-
if (typescript?.tsgo === false && typescript.typescriptPath === tsgoPath) typescript.typescriptPath = tryResolve("typescript", rootPath);
|
|
156
|
-
return normalizeTsgoConfig(config, rootPath);
|
|
157
|
-
}
|
|
158
|
-
];
|
|
159
|
-
};
|
|
160
|
-
export { withTsgoDefaults };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import node_path from "node:path";
|
|
3
|
-
const DEFAULT_RSPACK_CACHE_DIRECTORY = 'node_modules/.cache/rspack';
|
|
4
|
-
function sanitizeCachePathSegment(value) {
|
|
5
|
-
return value.replace(/[^a-zA-Z0-9._-]+/gu, '_');
|
|
6
|
-
}
|
|
7
|
-
function pathEndsWithSegment(filePath, segment) {
|
|
8
|
-
const normalized = filePath.replace(/[\\/]+$/u, '');
|
|
9
|
-
return normalized.split(/[\\/]+/u).at(-1) === segment;
|
|
10
|
-
}
|
|
11
|
-
function isolateEnvironmentBuildCacheDirectory(cacheDirectory, environmentName) {
|
|
12
|
-
const segment = sanitizeCachePathSegment(environmentName);
|
|
13
|
-
const baseDirectory = cacheDirectory || DEFAULT_RSPACK_CACHE_DIRECTORY;
|
|
14
|
-
return pathEndsWithSegment(baseDirectory, segment) ? baseDirectory : node_path.join(baseDirectory, segment);
|
|
15
|
-
}
|
|
16
|
-
const pluginEnvironmentBuildCacheIsolation = ()=>({
|
|
17
|
-
name: 'modern-js:environment-build-cache-isolation',
|
|
18
|
-
setup (api) {
|
|
19
|
-
api.modifyEnvironmentConfig({
|
|
20
|
-
order: 'post',
|
|
21
|
-
handler: (config, { name })=>{
|
|
22
|
-
const buildCache = config.performance.buildCache;
|
|
23
|
-
if (false === buildCache || void 0 === buildCache) return;
|
|
24
|
-
const buildCacheConfig = true === buildCache ? {} : buildCache;
|
|
25
|
-
return {
|
|
26
|
-
...config,
|
|
27
|
-
performance: {
|
|
28
|
-
...config.performance,
|
|
29
|
-
buildCache: {
|
|
30
|
-
...buildCacheConfig,
|
|
31
|
-
cacheDirectory: isolateEnvironmentBuildCacheDirectory(buildCacheConfig.cacheDirectory, name)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
export { isolateEnvironmentBuildCacheDirectory, pluginEnvironmentBuildCacheIsolation };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
const isRsdoctorEnabled = (config)=>{
|
|
3
|
-
if (void 0 === config) return false;
|
|
4
|
-
if ('boolean' == typeof config) return config;
|
|
5
|
-
if ('boolean' == typeof config?.enabled) return config.enabled;
|
|
6
|
-
return true;
|
|
7
|
-
};
|
|
8
|
-
const getRsdoctorPluginOptions = (config)=>{
|
|
9
|
-
if (config && 'object' == typeof config) return {
|
|
10
|
-
disableClientServer: config.disableClientServer ?? true
|
|
11
|
-
};
|
|
12
|
-
return {
|
|
13
|
-
disableClientServer: true
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
const pluginRsdoctor = (config)=>{
|
|
17
|
-
if (!isRsdoctorEnabled(config)) return null;
|
|
18
|
-
const pluginOptions = getRsdoctorPluginOptions(config);
|
|
19
|
-
return {
|
|
20
|
-
name: 'builder:rsdoctor',
|
|
21
|
-
setup (api) {
|
|
22
|
-
api.modifyBundlerChain(async (chain)=>{
|
|
23
|
-
const { RsdoctorRspackPlugin } = await import("@rsdoctor/rspack-plugin");
|
|
24
|
-
chain.plugin('rsdoctor').use(RsdoctorRspackPlugin, [
|
|
25
|
-
pluginOptions
|
|
26
|
-
]);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
export { pluginRsdoctor };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
const PERSISTENT_CACHE_MAX_AGE = 604800;
|
|
3
|
-
const PERSISTENT_CACHE_MAX_VERSIONS = 3;
|
|
4
|
-
const pluginRspack21 = ({ sourceImport } = {})=>({
|
|
5
|
-
name: 'modern-js:rspack-2-1-defaults',
|
|
6
|
-
setup (api) {
|
|
7
|
-
api.modifyRspackConfig((config)=>{
|
|
8
|
-
config.module ??= {};
|
|
9
|
-
config.module.parser ??= {};
|
|
10
|
-
config.module.parser.javascript ??= {};
|
|
11
|
-
config.module.parser.javascript.createRequire ??= true;
|
|
12
|
-
if ('object' == typeof config.cache && null !== config.cache && 'persistent' === config.cache.type) {
|
|
13
|
-
config.cache.maxAge ??= PERSISTENT_CACHE_MAX_AGE;
|
|
14
|
-
config.cache.maxVersions ??= PERSISTENT_CACHE_MAX_VERSIONS;
|
|
15
|
-
}
|
|
16
|
-
if (void 0 !== sourceImport) {
|
|
17
|
-
config.experiments ??= {};
|
|
18
|
-
config.experiments.sourceImport = sourceImport;
|
|
19
|
-
}
|
|
20
|
-
return config;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
export { pluginRspack21 };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "node:module";
|