@modern-js/app-tools 2.57.2-alpha.0 → 2.58.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/dist/cjs/builder/builder-webpack/index.js +1 -1
- package/dist/cjs/builder/generator/index.js +2 -2
- package/dist/cjs/builder/index.js +2 -2
- package/dist/cjs/commands/build.js +0 -19
- package/dist/cjs/commands/dev.js +0 -9
- package/dist/cjs/commands/index.js +8 -8
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugins/analyze/index.js +3 -3
- package/dist/cjs/plugins/deploy/dependencies/index.js +0 -1
- package/dist/cjs/plugins/deploy/dependencies/utils.js +0 -11
- package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -14
- package/dist/cjs/plugins/deploy/platforms/{netlify-handler.js → netlifyEntry.js} +4 -6
- package/dist/cjs/plugins/deploy/platforms/node.js +4 -13
- package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -14
- package/dist/cjs/plugins/deploy/platforms/{vercel-handler.js → vercelEntry.js} +1 -27
- package/dist/cjs/utils/config.js +1 -1
- package/dist/cjs/utils/loadPlugins.js +1 -1
- package/dist/cjs/utils/register.js +22 -49
- package/dist/esm/builder/builder-rspack/adapterCopy.js +4 -3
- package/dist/esm/builder/generator/getBuilderEnvironments.js +2 -0
- package/dist/esm/builder/generator/index.js +1 -1
- package/dist/esm/builder/index.js +2 -2
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +1 -1
- package/dist/esm/commands/build.js +16 -9
- package/dist/esm/commands/dev.js +55 -37
- package/dist/esm/commands/index.js +7 -7
- package/dist/esm/index.js +1 -42
- package/dist/esm/plugins/analyze/index.js +10 -6
- package/dist/esm/plugins/deploy/dependencies/index.js +16 -8
- package/dist/esm/plugins/deploy/dependencies/utils.js +15 -7
- package/dist/esm/utils/createServer.js +1 -1
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +2 -2
- package/dist/esm-node/builder/generator/getBuilderEnvironments.js +1 -1
- package/dist/esm-node/builder/generator/index.js +1 -1
- package/dist/esm-node/builder/index.js +2 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +1 -1
- package/dist/esm-node/commands/build.js +3 -0
- package/dist/esm-node/commands/dev.js +24 -16
- package/dist/esm-node/commands/index.js +7 -7
- package/dist/esm-node/index.js +1 -17
- package/dist/esm-node/plugins/analyze/index.js +7 -5
- package/dist/esm-node/plugins/deploy/dependencies/index.js +15 -7
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +11 -2
- package/dist/esm-node/utils/createServer.js +1 -1
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/package.json +18 -18
- package/dist/cjs/esm/esbuild-loader.mjs +0 -20
- package/dist/cjs/esm/register-esm.mjs +0 -65
- package/dist/cjs/esm/ts-node-loader.mjs +0 -21
- package/dist/cjs/esm/utils.mjs +0 -43
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +0 -3
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +0 -1
- package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +0 -3
- package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +0 -3
- package/dist/esm/custom-loader.mjs +0 -41
- package/dist/esm/register-esm.mjs +0 -22
- package/dist/esm-node/esm/esbuild-loader.js +0 -39
- package/dist/esm-node/esm/register-esm.js +0 -39
- package/dist/esm-node/esm/ts-node-loader.js +0 -42
- package/dist/types/esm/esbuild-loader.d.mts +0 -6
- package/dist/types/esm/register-esm.d.mts +0 -5
- package/dist/types/esm/ts-node-loader.d.mts +0 -6
- package/dist/types/esm/utils.d.mts +0 -6
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +0 -1
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +0 -1
- package/dist/types/plugins/deploy/platforms/netlify-handler.d.cts +0 -1
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.cts +0 -2
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +0 -2
- package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +0 -1
- /package/dist/cjs/plugins/deploy/platforms/{node-entry.js → nodeEntry.js} +0 -0
- /package/dist/types/plugins/deploy/platforms/{node-entry.d.ts → nodeEntry.d.ts} +0 -0
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { ResolvedConfigContext } from "@modern-js/core";
|
|
3
|
-
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from "@modern-js/utils";
|
|
3
|
+
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
|
|
4
4
|
import { createDevServer } from "@modern-js/server";
|
|
5
5
|
import { applyPlugins } from "@modern-js/prod-server";
|
|
6
6
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
|
7
|
+
import { registerCompiler } from "../utils/register";
|
|
7
8
|
import { printInstructions } from "../utils/printInstructions";
|
|
8
9
|
import { setServer } from "../utils/createServer";
|
|
9
10
|
import { generateRoutes } from "../utils/routes";
|
|
10
11
|
import { buildServerConfig } from "../utils/config";
|
|
11
|
-
const dev = async (api, options, devServerOptions
|
|
12
|
-
var _normalizedConfig_source, _normalizedConfig_tools;
|
|
12
|
+
const dev = async (api, options, devServerOptions) => {
|
|
13
|
+
var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev;
|
|
13
14
|
if (options.analyze) {
|
|
14
15
|
process.env.BUNDLE_ANALYZE = "true";
|
|
15
16
|
}
|
|
16
17
|
let normalizedConfig = api.useResolvedConfigContext();
|
|
17
18
|
const appContext = api.useAppContext();
|
|
18
19
|
const hookRunners = api.useHookRunners();
|
|
19
|
-
|
|
20
|
-
await registerEsm({
|
|
21
|
-
appDir: appContext.appDirectory,
|
|
22
|
-
distDir: appContext.distDirectory,
|
|
23
|
-
alias: (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias
|
|
24
|
-
});
|
|
20
|
+
await registerCompiler(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias);
|
|
25
21
|
normalizedConfig = {
|
|
26
22
|
...normalizedConfig,
|
|
27
23
|
cliOptions: options
|
|
@@ -64,20 +60,32 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
|
64
60
|
plugins: pluginInstances,
|
|
65
61
|
...devServerOptions
|
|
66
62
|
};
|
|
63
|
+
const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
|
67
64
|
if (apiOnly) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
const { server } = await createDevServer({
|
|
66
|
+
...serverOptions,
|
|
67
|
+
runCompile: false
|
|
68
|
+
}, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins);
|
|
69
|
+
server.listen({
|
|
72
70
|
port,
|
|
73
71
|
host
|
|
74
72
|
}, () => {
|
|
75
73
|
printInstructions(hookRunners, appContext, normalizedConfig);
|
|
76
74
|
});
|
|
77
75
|
} else {
|
|
78
|
-
const { server } = await
|
|
79
|
-
serverOptions,
|
|
80
|
-
|
|
76
|
+
const { server, afterListen } = await createDevServer({
|
|
77
|
+
...serverOptions,
|
|
78
|
+
builder: appContext.builder
|
|
79
|
+
}, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins);
|
|
80
|
+
server.listen({
|
|
81
|
+
port,
|
|
82
|
+
host
|
|
83
|
+
}, async (err) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
logger.error("Occur error %s, when start dev server", err);
|
|
86
|
+
}
|
|
87
|
+
logger.debug("listen dev server done");
|
|
88
|
+
await afterListen();
|
|
81
89
|
});
|
|
82
90
|
setServer(server);
|
|
83
91
|
}
|
|
@@ -5,7 +5,7 @@ const devCommand = async (program, api) => {
|
|
|
5
5
|
const runner = api.useHookRunners();
|
|
6
6
|
const devToolMetas = await runner.registerDev();
|
|
7
7
|
const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("--web-only", i18n.t(localeKeys.command.dev.webOnly)).action(async (options) => {
|
|
8
|
-
const { dev } = await import("./dev
|
|
8
|
+
const { dev } = await import("./dev");
|
|
9
9
|
await dev(api, options);
|
|
10
10
|
});
|
|
11
11
|
for (const meta of devToolMetas) {
|
|
@@ -28,7 +28,7 @@ const buildCommand = async (program, api) => {
|
|
|
28
28
|
const runner = api.useHookRunners();
|
|
29
29
|
const platformBuilders = await runner.registerBuildPlatform();
|
|
30
30
|
const buildProgram = program.command("build").usage("[options]").description(i18n.t(localeKeys.command.build.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).action(async (options) => {
|
|
31
|
-
const { build } = await import("./build
|
|
31
|
+
const { build } = await import("./build");
|
|
32
32
|
await build(api, options);
|
|
33
33
|
});
|
|
34
34
|
for (const platformBuilder of platformBuilders) {
|
|
@@ -47,17 +47,17 @@ const buildCommand = async (program, api) => {
|
|
|
47
47
|
};
|
|
48
48
|
const serverCommand = (program, api) => {
|
|
49
49
|
program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async () => {
|
|
50
|
-
const { start } = await import("./serve
|
|
50
|
+
const { start } = await import("./serve");
|
|
51
51
|
await start(api);
|
|
52
52
|
});
|
|
53
53
|
};
|
|
54
54
|
const deployCommand = (program, api) => {
|
|
55
55
|
program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options) => {
|
|
56
56
|
if (!options.skipBuild) {
|
|
57
|
-
const { build } = await import("./build
|
|
57
|
+
const { build } = await import("./build");
|
|
58
58
|
await build(api);
|
|
59
59
|
}
|
|
60
|
-
const { deploy } = await import("./deploy
|
|
60
|
+
const { deploy } = await import("./deploy");
|
|
61
61
|
await deploy(api, options);
|
|
62
62
|
process.exit(0);
|
|
63
63
|
});
|
|
@@ -71,8 +71,8 @@ const newCommand = (program, locale) => {
|
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
73
|
const inspectCommand = (program, api) => {
|
|
74
|
-
program.command("inspect").description("inspect the internal configs").option(`--env <env>`, i18n.t(localeKeys.command.inspect.env), "development").option("--output <output>", i18n.t(localeKeys.command.inspect.output), "
|
|
75
|
-
const { inspect } = await import("./inspect
|
|
74
|
+
program.command("inspect").description("inspect the internal configs").option(`--env <env>`, i18n.t(localeKeys.command.inspect.env), "development").option("--output <output>", i18n.t(localeKeys.command.inspect.output), "./").option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async (options) => {
|
|
75
|
+
const { inspect } = await import("./inspect");
|
|
76
76
|
inspect(api, options);
|
|
77
77
|
});
|
|
78
78
|
};
|
package/dist/esm-node/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { lintPlugin } from "@modern-js/plugin-lint";
|
|
3
|
-
import { cleanRequireCache, emptyDir, getCommand, getArgv
|
|
3
|
+
import { cleanRequireCache, emptyDir, getCommand, getArgv } from "@modern-js/utils";
|
|
4
4
|
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
|
5
5
|
import initializePlugin from "./plugins/initialize";
|
|
6
6
|
import analyzePlugin from "./plugins/analyze";
|
|
@@ -47,7 +47,6 @@ const appTools = (options = {
|
|
|
47
47
|
...appContext,
|
|
48
48
|
toolsType: "app-tools"
|
|
49
49
|
});
|
|
50
|
-
const nestedRoutes = {};
|
|
51
50
|
const locale = getLocaleLanguage();
|
|
52
51
|
i18n.changeLanguage({
|
|
53
52
|
locale
|
|
@@ -112,21 +111,6 @@ const appTools = (options = {
|
|
|
112
111
|
cleanRequireCache([
|
|
113
112
|
require.resolve("./plugins/analyze")
|
|
114
113
|
]);
|
|
115
|
-
},
|
|
116
|
-
async modifyFileSystemRoutes({ entrypoint, routes }) {
|
|
117
|
-
nestedRoutes[entrypoint.entryName] = routes;
|
|
118
|
-
return {
|
|
119
|
-
entrypoint,
|
|
120
|
-
routes
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
|
-
async beforeGenerateRoutes({ entrypoint, code }) {
|
|
124
|
-
const { distDirectory } = api.useAppContext();
|
|
125
|
-
await fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes);
|
|
126
|
-
return {
|
|
127
|
-
entrypoint,
|
|
128
|
-
code
|
|
129
|
-
};
|
|
130
114
|
}
|
|
131
115
|
};
|
|
132
116
|
}
|
|
@@ -7,7 +7,6 @@ import { getSelectedEntries } from "../../utils/getSelectedEntries";
|
|
|
7
7
|
import { initialNormalizedConfig } from "../../config";
|
|
8
8
|
import { createBuilderGenerator } from "../../builder";
|
|
9
9
|
import { checkIsBuildCommands } from "./utils";
|
|
10
|
-
import { compatibleRequire } from "@modern-js/utils";
|
|
11
10
|
const debug = createDebugger("plugin-analyze");
|
|
12
11
|
var analyze_default = ({ bundler }) => ({
|
|
13
12
|
name: "@modern-js/plugin-analyze",
|
|
@@ -45,9 +44,9 @@ var analyze_default = ({ bundler }) => ({
|
|
|
45
44
|
return;
|
|
46
45
|
}
|
|
47
46
|
const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
import("./getBundleEntry"),
|
|
48
|
+
import("./getServerRoutes"),
|
|
49
|
+
import("./getHtmlTemplate")
|
|
51
50
|
]);
|
|
52
51
|
const { entrypoints } = await hookRunners.modifyEntrypoints({
|
|
53
52
|
entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
|
|
@@ -100,7 +99,10 @@ var analyze_default = ({ bundler }) => ({
|
|
|
100
99
|
normalizedConfig,
|
|
101
100
|
appContext
|
|
102
101
|
});
|
|
103
|
-
builder.onBeforeBuild(async ({ bundlerConfigs }) => {
|
|
102
|
+
builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile }) => {
|
|
103
|
+
if (!isFirstCompile) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
104
106
|
const hookRunners2 = api.useHookRunners();
|
|
105
107
|
await generateRoutes(appContext);
|
|
106
108
|
await hookRunners2.beforeBuild({
|
|
@@ -2,12 +2,19 @@ import path from "node:path";
|
|
|
2
2
|
import { fs as fse, pkgUp, semver } from "@modern-js/utils";
|
|
3
3
|
import { readPackageJSON } from "pkg-types";
|
|
4
4
|
import { parseNodeModulePath } from "mlly";
|
|
5
|
-
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
|
|
6
|
-
|
|
5
|
+
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive, isSubPath } from "./utils";
|
|
6
|
+
import { nodeFileTrace } from "@vercel/nft";
|
|
7
|
+
const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions }) => {
|
|
7
8
|
const base = "/";
|
|
8
9
|
const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
|
|
9
|
-
const fileTrace = await traceFiles(
|
|
10
|
+
const fileTrace = await traceFiles({
|
|
11
|
+
entryFiles: entryFiles.concat(includeEntries),
|
|
12
|
+
serverRootDir,
|
|
13
|
+
base,
|
|
14
|
+
traceOptions
|
|
15
|
+
});
|
|
10
16
|
const currentProjectModules = path.join(appDir, "node_modules");
|
|
17
|
+
const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
|
|
11
18
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
|
12
19
|
...fileTrace.reasons.entries()
|
|
13
20
|
].map(async ([_path, reasons]) => {
|
|
@@ -15,7 +22,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
15
22
|
return;
|
|
16
23
|
}
|
|
17
24
|
const filePath = await resolveTracedPath(base, _path);
|
|
18
|
-
if (
|
|
25
|
+
if (isSubPath(serverRootDir, filePath) || isSubPath(appDir, filePath) && !isSubPath(currentProjectModules, filePath)) {
|
|
19
26
|
return;
|
|
20
27
|
}
|
|
21
28
|
if (!await isFile(filePath)) {
|
|
@@ -38,7 +45,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
38
45
|
const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
|
|
39
46
|
cwd: path.dirname(filePath)
|
|
40
47
|
});
|
|
41
|
-
if (packageJsonPath) {
|
|
48
|
+
if (packageJsonPath && isSubPath(dependencySearchRoot, packageJsonPath)) {
|
|
42
49
|
const packageJson = await fse.readJSON(packageJsonPath);
|
|
43
50
|
pkgPath = baseDir = path.dirname(packageJsonPath);
|
|
44
51
|
subpath = path.relative(baseDir, filePath);
|
|
@@ -55,7 +62,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
55
62
|
path: filePath,
|
|
56
63
|
parents,
|
|
57
64
|
isDirectDep: parents.some((parent) => {
|
|
58
|
-
return
|
|
65
|
+
return isSubPath(appDir, parent) && !isSubPath(currentProjectModules, parent);
|
|
59
66
|
}),
|
|
60
67
|
subpath,
|
|
61
68
|
pkgName,
|
|
@@ -189,5 +196,6 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
189
196
|
await fse.writeJSON(outputPkgPath, finalPkgJson);
|
|
190
197
|
};
|
|
191
198
|
export {
|
|
192
|
-
handleDependencies
|
|
199
|
+
handleDependencies,
|
|
200
|
+
nodeFileTrace
|
|
193
201
|
};
|
|
@@ -98,17 +98,26 @@ const findPackageParents = (pkg, version, tracedFiles) => {
|
|
|
98
98
|
];
|
|
99
99
|
return parentPkgs.filter((parentPkg) => parentPkg);
|
|
100
100
|
};
|
|
101
|
-
const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
|
|
101
|
+
const traceFiles = async ({ entryFiles, serverRootDir, base = "/", traceOptions }) => {
|
|
102
102
|
return await nodeFileTrace(entryFiles, {
|
|
103
103
|
base,
|
|
104
|
-
processCwd: serverRootDir
|
|
104
|
+
processCwd: serverRootDir,
|
|
105
|
+
...traceOptions
|
|
105
106
|
});
|
|
106
107
|
};
|
|
107
108
|
const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
|
|
109
|
+
const isSubPath = (parentPath, childPath) => {
|
|
110
|
+
if (!parentPath || !childPath) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const relative = path.relative(parentPath, childPath);
|
|
114
|
+
return relative && !relative.startsWith("..");
|
|
115
|
+
};
|
|
108
116
|
export {
|
|
109
117
|
findEntryFiles,
|
|
110
118
|
findPackageParents,
|
|
111
119
|
isFile,
|
|
120
|
+
isSubPath,
|
|
112
121
|
linkPackage,
|
|
113
122
|
readDirRecursive,
|
|
114
123
|
resolveTracedPath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack
|
|
1
|
+
export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack").createRspackBuilderForModern>;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.58.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -87,33 +87,33 @@
|
|
|
87
87
|
"mlly": "^1.6.1",
|
|
88
88
|
"pkg-types": "^1.1.0",
|
|
89
89
|
"std-env": "^3.7.0",
|
|
90
|
-
"@modern-js/core": "2.
|
|
91
|
-
"@modern-js/
|
|
92
|
-
"@modern-js/
|
|
93
|
-
"@modern-js/plugin-
|
|
94
|
-
"@modern-js/plugin": "2.
|
|
95
|
-
"@modern-js/
|
|
96
|
-
"@modern-js/
|
|
97
|
-
"@modern-js/
|
|
98
|
-
"@modern-js/server
|
|
99
|
-
"@modern-js/server-utils": "2.
|
|
100
|
-
"@modern-js/types": "2.
|
|
101
|
-
"@modern-js/
|
|
102
|
-
"@modern-js/
|
|
103
|
-
"@modern-js/
|
|
90
|
+
"@modern-js/core": "2.58.0",
|
|
91
|
+
"@modern-js/plugin-data-loader": "2.58.0",
|
|
92
|
+
"@modern-js/node-bundle-require": "2.58.0",
|
|
93
|
+
"@modern-js/plugin-lint": "2.58.0",
|
|
94
|
+
"@modern-js/rsbuild-plugin-esbuild": "2.58.0",
|
|
95
|
+
"@modern-js/plugin": "2.58.0",
|
|
96
|
+
"@modern-js/plugin-i18n": "2.58.0",
|
|
97
|
+
"@modern-js/prod-server": "2.58.0",
|
|
98
|
+
"@modern-js/server": "2.58.0",
|
|
99
|
+
"@modern-js/server-utils": "2.58.0",
|
|
100
|
+
"@modern-js/types": "2.58.0",
|
|
101
|
+
"@modern-js/uni-builder": "2.58.0",
|
|
102
|
+
"@modern-js/server-core": "2.58.0",
|
|
103
|
+
"@modern-js/utils": "2.58.0"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
106
|
"@rsbuild/plugin-swc": "1.0.1-beta.9",
|
|
107
107
|
"@types/babel__traverse": "7.18.5",
|
|
108
108
|
"@types/jest": "^29",
|
|
109
|
-
"@types/node": "^
|
|
109
|
+
"@types/node": "^14",
|
|
110
110
|
"jest": "^29",
|
|
111
111
|
"ts-node": "^10.9.1",
|
|
112
112
|
"tsconfig-paths": "^4.2.0",
|
|
113
113
|
"typescript": "^5",
|
|
114
114
|
"webpack": "^5.93.0",
|
|
115
|
-
"@scripts/jest-config": "2.
|
|
116
|
-
"@scripts/build": "2.
|
|
115
|
+
"@scripts/jest-config": "2.58.0",
|
|
116
|
+
"@scripts/build": "2.58.0"
|
|
117
117
|
},
|
|
118
118
|
"sideEffects": false,
|
|
119
119
|
"publishConfig": {
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { pathToFileURL } from 'url';
|
|
2
|
-
import { createMatchPath } from './utils.mjs';
|
|
3
|
-
|
|
4
|
-
let matchPath;
|
|
5
|
-
export async function initialize({ appDir, alias, tsconfigPath }) {
|
|
6
|
-
matchPath = createMatchPath({
|
|
7
|
-
alias,
|
|
8
|
-
appDir,
|
|
9
|
-
tsconfigPath,
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function resolve(specifier, context, defaultResolve) {
|
|
14
|
-
const match = matchPath(specifier);
|
|
15
|
-
return match
|
|
16
|
-
? defaultResolve(pathToFileURL(match).href, context)
|
|
17
|
-
: defaultResolve(specifier, context);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { load } from 'esbuild-register/loader';
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { fs, readTsConfigByFile } from '@modern-js/utils';
|
|
3
|
-
|
|
4
|
-
const checkDep = async dep => {
|
|
5
|
-
try {
|
|
6
|
-
await import(dep);
|
|
7
|
-
return true;
|
|
8
|
-
} catch (error) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const registerEsm = async ({ appDir, distDir, alias }) => {
|
|
14
|
-
const nodeVersion = process.versions.node;
|
|
15
|
-
const versionArr = nodeVersion.split('.').map(Number);
|
|
16
|
-
if (versionArr[0] < 18 || (versionArr[0] === 18 && versionArr[1] < 19)) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
`The node version of the esm project must be greater than 18.19.0, current version is ${nodeVersion}`,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
const hasTsNode = await checkDep('ts-node');
|
|
22
|
-
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
23
|
-
const tsconfigPath = path.resolve(appDir, TS_CONFIG_FILENAME);
|
|
24
|
-
const hasTsconfig = await fs.pathExists(tsconfigPath);
|
|
25
|
-
const { register } = await import('node:module');
|
|
26
|
-
if (hasTsNode && hasTsconfig) {
|
|
27
|
-
// These can be overridden by ts-node options in tsconfig.json
|
|
28
|
-
process.env.TS_NODE_TRANSPILE_ONLY = true;
|
|
29
|
-
process.env.TS_NODE_PROJECT = tsconfigPath;
|
|
30
|
-
process.env.TS_NODE_SCOPE = true;
|
|
31
|
-
process.env.TS_NODE_FILES = true;
|
|
32
|
-
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(
|
|
33
|
-
appDir,
|
|
34
|
-
distDir,
|
|
35
|
-
)}/`;
|
|
36
|
-
register('./ts-node-loader.mjs', import.meta.url, {
|
|
37
|
-
data: {
|
|
38
|
-
appDir,
|
|
39
|
-
distDir,
|
|
40
|
-
alias,
|
|
41
|
-
tsconfigPath,
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
process.env.MODERN_NODE_LOADER = 'esbuild';
|
|
46
|
-
let tsConfig = {};
|
|
47
|
-
if (hasTsconfig) {
|
|
48
|
-
tsConfig = readTsConfigByFile(tsconfigPath);
|
|
49
|
-
}
|
|
50
|
-
const esbuildRegister = await import('esbuild-register/dist/node');
|
|
51
|
-
esbuildRegister.register({
|
|
52
|
-
tsconfigRaw: hasTsconfig ? tsConfig : undefined,
|
|
53
|
-
hookIgnoreNodeModules: true,
|
|
54
|
-
hookMatcher: fileName => !fileName.startsWith(distDir),
|
|
55
|
-
});
|
|
56
|
-
register('./esbuild-loader.mjs', import.meta.url, {
|
|
57
|
-
data: {
|
|
58
|
-
appDir,
|
|
59
|
-
distDir,
|
|
60
|
-
alias,
|
|
61
|
-
tsconfigPath,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { pathToFileURL } from 'url';
|
|
2
|
-
import { resolve as tsNodeResolve } from 'ts-node/esm';
|
|
3
|
-
import { createMatchPath } from './utils.mjs';
|
|
4
|
-
|
|
5
|
-
let matchPath;
|
|
6
|
-
export async function initialize({ appDir, alias, tsconfigPath }) {
|
|
7
|
-
matchPath = createMatchPath({
|
|
8
|
-
alias,
|
|
9
|
-
appDir,
|
|
10
|
-
tsconfigPath,
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function resolve(specifier, context, defaultResolve) {
|
|
15
|
-
const match = matchPath(specifier);
|
|
16
|
-
return match
|
|
17
|
-
? tsNodeResolve(pathToFileURL(match).href, context, defaultResolve)
|
|
18
|
-
: tsNodeResolve(specifier, context, defaultResolve);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { transformSource, load } from 'ts-node/esm';
|
package/dist/cjs/esm/utils.mjs
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
import tsConfigPaths from '@modern-js/utils/tsconfig-paths';
|
|
4
|
-
import { getAliasConfig } from '@modern-js/utils';
|
|
5
|
-
|
|
6
|
-
const require = createRequire(import.meta.url);
|
|
7
|
-
export function createMatchPath({ alias, appDir, tsconfigPath }) {
|
|
8
|
-
const aliasConfig = getAliasConfig(alias, {
|
|
9
|
-
appDirectory: appDir,
|
|
10
|
-
tsconfigPath,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
|
|
14
|
-
|
|
15
|
-
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
16
|
-
let tsPath = paths[key];
|
|
17
|
-
// Do some special handling for Modern.js's internal alias, we can drop it in the next version
|
|
18
|
-
if (
|
|
19
|
-
typeof tsPath === 'string' &&
|
|
20
|
-
key.startsWith('@') &&
|
|
21
|
-
tsPath.startsWith('@')
|
|
22
|
-
) {
|
|
23
|
-
try {
|
|
24
|
-
tsPath = require.resolve(tsPath, {
|
|
25
|
-
paths: [appDir],
|
|
26
|
-
});
|
|
27
|
-
} catch {}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
|
|
31
|
-
tsPath = path.relative(absoluteBaseUrl, tsPath);
|
|
32
|
-
}
|
|
33
|
-
if (typeof tsPath === 'string') {
|
|
34
|
-
tsPath = [tsPath];
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
...o,
|
|
38
|
-
[`${key}`]: tsPath,
|
|
39
|
-
};
|
|
40
|
-
}, {});
|
|
41
|
-
|
|
42
|
-
return tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
|
|
43
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { handler as default } from './netlify-handler.cjs';
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { pathToFileURL } from 'url';
|
|
2
|
-
import { resolve as tsNodeResolve } from 'ts-node/esm';
|
|
3
|
-
import * as tsConfigPaths from 'tsconfig-paths';
|
|
4
|
-
import fs from 'fs/promises'
|
|
5
|
-
import { getAliasConfig } from '@modern-js/utils';
|
|
6
|
-
import path from 'path'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let matchPath;
|
|
10
|
-
export function initialize({ appDir, alias }){
|
|
11
|
-
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
12
|
-
const aliasConfig = getAliasConfig(alias, {
|
|
13
|
-
appDirectory: appDir,
|
|
14
|
-
tsconfigPath: path.resolve(appDir, TS_CONFIG_FILENAME),
|
|
15
|
-
});
|
|
16
|
-
const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
|
|
17
|
-
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
18
|
-
let tsPath = paths[key];
|
|
19
|
-
if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
|
|
20
|
-
tsPath = path.relative(absoluteBaseUrl, tsPath);
|
|
21
|
-
}
|
|
22
|
-
if (typeof tsPath === 'string') {
|
|
23
|
-
tsPath = [tsPath];
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
...o,
|
|
27
|
-
[`${key}`]: tsPath,
|
|
28
|
-
};
|
|
29
|
-
}, {});
|
|
30
|
-
|
|
31
|
-
matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function resolve(specifier, context, defaultResolve) {
|
|
35
|
-
const match = matchPath(specifier);
|
|
36
|
-
return match
|
|
37
|
-
? tsNodeResolve(pathToFileURL(match).href, context, defaultResolve)
|
|
38
|
-
: tsNodeResolve(specifier, context, defaultResolve);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { transformSource, load } from 'ts-node/esm';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { register } from 'node:module';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
export const registerEsm = async ({
|
|
5
|
-
appDir,
|
|
6
|
-
distDir,
|
|
7
|
-
alias
|
|
8
|
-
}) => {
|
|
9
|
-
// These can be overridden by ts-node options in tsconfig.json
|
|
10
|
-
process.env.TS_NODE_TRANSPILE_ONLY = true;
|
|
11
|
-
process.env.TS_NODE_PROJECT = path.join(appDir, 'tsconfig.json');
|
|
12
|
-
process.env.TS_NODE_SCOPE = true;
|
|
13
|
-
process.env.TS_NODE_FILES = true;
|
|
14
|
-
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(appDir, distDir)}/`
|
|
15
|
-
register('./custom-loader.mjs', import.meta.url, {
|
|
16
|
-
data: {
|
|
17
|
-
appDir,
|
|
18
|
-
distDir,
|
|
19
|
-
alias
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { pathToFileURL } from "url";
|
|
2
|
-
import * as tsConfigPaths from "@modern-js/utils/tsconfig-paths";
|
|
3
|
-
import { getAliasConfig } from "@modern-js/utils";
|
|
4
|
-
import path from "path";
|
|
5
|
-
let matchPath;
|
|
6
|
-
function initialize({ appDir, alias }) {
|
|
7
|
-
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
8
|
-
const aliasConfig = getAliasConfig(alias, {
|
|
9
|
-
appDirectory: appDir,
|
|
10
|
-
tsconfigPath: path.resolve(appDir, TS_CONFIG_FILENAME)
|
|
11
|
-
});
|
|
12
|
-
const { paths = {}, absoluteBaseUrl = "./" } = aliasConfig;
|
|
13
|
-
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
14
|
-
let tsPath = paths[key];
|
|
15
|
-
if (typeof tsPath === "string" && path.isAbsolute(tsPath)) {
|
|
16
|
-
tsPath = path.relative(absoluteBaseUrl, tsPath);
|
|
17
|
-
}
|
|
18
|
-
if (typeof tsPath === "string") {
|
|
19
|
-
tsPath = [
|
|
20
|
-
tsPath
|
|
21
|
-
];
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
...o,
|
|
25
|
-
[`${key}`]: tsPath
|
|
26
|
-
};
|
|
27
|
-
}, {});
|
|
28
|
-
matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
|
|
29
|
-
}
|
|
30
|
-
function resolve(specifier, context, defaultResolve) {
|
|
31
|
-
const match = matchPath(specifier);
|
|
32
|
-
return match ? defaultResolve(pathToFileURL(match).href, context) : defaultResolve(specifier, context);
|
|
33
|
-
}
|
|
34
|
-
import { load } from "esbuild-register/loader";
|
|
35
|
-
export {
|
|
36
|
-
initialize,
|
|
37
|
-
load,
|
|
38
|
-
resolve
|
|
39
|
-
};
|