@modern-js/app-tools 2.57.1 → 2.57.2-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +2 -2
- 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 +19 -0
- package/dist/cjs/commands/dev.js +9 -0
- package/dist/cjs/commands/index.js +9 -9
- package/dist/cjs/esm/esbuild-loader.mjs +20 -0
- package/dist/cjs/esm/register-esm.mjs +65 -0
- package/dist/cjs/esm/ts-node-loader.mjs +21 -0
- package/dist/cjs/esm/utils.mjs +43 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugins/analyze/index.js +7 -4
- package/dist/cjs/plugins/deploy/dependencies/index.js +13 -4
- package/dist/cjs/plugins/deploy/dependencies/utils.js +14 -2
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +3 -0
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +1 -0
- package/dist/cjs/plugins/deploy/platforms/{netlifyEntry.js → netlify-handler.js} +6 -4
- package/dist/cjs/plugins/deploy/platforms/netlify.js +14 -5
- package/dist/cjs/plugins/deploy/platforms/node.js +13 -4
- package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +3 -0
- package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +3 -0
- package/dist/cjs/plugins/deploy/platforms/{vercelEntry.js → vercel-handler.js} +27 -1
- package/dist/cjs/plugins/deploy/platforms/vercel.js +14 -5
- package/dist/cjs/utils/config.js +1 -1
- package/dist/cjs/utils/loadPlugins.js +1 -1
- package/dist/cjs/utils/register.js +49 -22
- package/dist/esm/builder/generator/getBuilderEnvironments.js +0 -2
- 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 +9 -16
- package/dist/esm/commands/dev.js +37 -55
- package/dist/esm/commands/index.js +6 -6
- package/dist/esm/custom-loader.mjs +41 -0
- package/dist/esm/index.js +42 -1
- package/dist/esm/plugins/analyze/index.js +4 -3
- package/dist/esm/plugins/deploy/dependencies/index.js +5 -6
- package/dist/esm/plugins/deploy/dependencies/utils.js +0 -8
- package/dist/esm/register-esm.mjs +22 -0
- package/dist/esm/utils/createServer.js +1 -1
- 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 +0 -3
- package/dist/esm-node/commands/dev.js +16 -24
- package/dist/esm-node/commands/index.js +6 -6
- package/dist/esm-node/esm/esbuild-loader.js +39 -0
- package/dist/esm-node/esm/register-esm.js +39 -0
- package/dist/esm-node/esm/ts-node-loader.js +42 -0
- package/dist/esm-node/index.js +17 -1
- package/dist/esm-node/plugins/analyze/index.js +4 -3
- package/dist/esm-node/plugins/deploy/dependencies/index.js +4 -5
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +0 -8
- package/dist/esm-node/utils/createServer.js +1 -1
- package/dist/types/builder/generator/getBuilderEnvironments.d.ts +1 -1
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/esm/esbuild-loader.d.mts +6 -0
- package/dist/types/esm/register-esm.d.mts +5 -0
- package/dist/types/esm/ts-node-loader.d.mts +6 -0
- package/dist/types/esm/utils.d.mts +6 -0
- package/dist/types/plugins/deploy/dependencies/index.d.ts +11 -2
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +7 -1
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +1 -0
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/netlify-handler.d.cts +1 -0
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.cts +2 -0
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +2 -0
- package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +1 -0
- package/package.json +10 -10
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +0 -2
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
- /package/dist/cjs/plugins/deploy/platforms/{nodeEntry.js → node-entry.js} +0 -0
- /package/dist/types/plugins/deploy/platforms/{nodeEntry.d.ts → node-entry.d.ts} +0 -0
@@ -7,10 +7,10 @@ import path from "node:path";
|
|
7
7
|
import { fs as fse, pkgUp, semver } from "@modern-js/utils";
|
8
8
|
import { readPackageJSON } from "pkg-types";
|
9
9
|
import { parseNodeModulePath } from "mlly";
|
10
|
-
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive
|
10
|
+
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
|
11
11
|
var handleDependencies = function() {
|
12
12
|
var _ref = _async_to_generator(function(param) {
|
13
|
-
var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules,
|
13
|
+
var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, shouldCopyWholePackage, _tracedPackageVersion_files, allFiles, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson;
|
14
14
|
return _ts_generator(this, function(_state) {
|
15
15
|
switch (_state.label) {
|
16
16
|
case 0:
|
@@ -29,7 +29,6 @@ var handleDependencies = function() {
|
|
29
29
|
case 2:
|
30
30
|
fileTrace = _state.sent();
|
31
31
|
currentProjectModules = path.join(appDir, "node_modules");
|
32
|
-
dependencySearchRoot = path.resolve(appDir, "../../../../../../");
|
33
32
|
_ = Object.fromEntries;
|
34
33
|
return [
|
35
34
|
4,
|
@@ -51,7 +50,7 @@ var handleDependencies = function() {
|
|
51
50
|
];
|
52
51
|
case 1:
|
53
52
|
filePath = _state2.sent();
|
54
|
-
if (
|
53
|
+
if (filePath.startsWith(serverRootDir) || filePath.startsWith(appDir) && !filePath.startsWith(currentProjectModules)) {
|
55
54
|
return [
|
56
55
|
2
|
57
56
|
];
|
@@ -106,7 +105,7 @@ var handleDependencies = function() {
|
|
106
105
|
_state2.label = 6;
|
107
106
|
case 6:
|
108
107
|
packageJsonPath = _tmp;
|
109
|
-
if (!
|
108
|
+
if (!packageJsonPath)
|
110
109
|
return [
|
111
110
|
3,
|
112
111
|
8
|
@@ -139,7 +138,7 @@ var handleDependencies = function() {
|
|
139
138
|
path: filePath,
|
140
139
|
parents,
|
141
140
|
isDirectDep: parents.some(function(parent) {
|
142
|
-
return
|
141
|
+
return parent.startsWith(appDir) && !parent.startsWith(currentProjectModules);
|
143
142
|
}),
|
144
143
|
subpath,
|
145
144
|
pkgName: pkgName2,
|
@@ -374,18 +374,10 @@ var resolveTracedPath = function() {
|
|
374
374
|
return _ref.apply(this, arguments);
|
375
375
|
};
|
376
376
|
}();
|
377
|
-
var isSubPath = function(parentPath, childPath) {
|
378
|
-
if (!parentPath || !childPath) {
|
379
|
-
return false;
|
380
|
-
}
|
381
|
-
var relative = path.relative(parentPath, childPath);
|
382
|
-
return relative && !relative.startsWith("..");
|
383
|
-
};
|
384
377
|
export {
|
385
378
|
findEntryFiles,
|
386
379
|
findPackageParents,
|
387
380
|
isFile,
|
388
|
-
isSubPath,
|
389
381
|
linkPackage,
|
390
382
|
readDirRecursive,
|
391
383
|
resolveTracedPath,
|
@@ -0,0 +1,22 @@
|
|
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
|
+
};
|
@@ -19,7 +19,7 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
|
|
19
19
|
const serverEntries = {};
|
20
20
|
for (const entry in entries) {
|
21
21
|
const v = entries[entry];
|
22
|
-
serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"))
|
22
|
+
serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"));
|
23
23
|
}
|
24
24
|
const environments = {
|
25
25
|
web: {
|
@@ -17,7 +17,7 @@ async function generateBuilder(options, bundlerType) {
|
|
17
17
|
return builder;
|
18
18
|
}
|
19
19
|
async function applyBuilderPlugins(builder, options) {
|
20
|
-
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins");
|
20
|
+
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins/index.js");
|
21
21
|
builder.addPlugins([
|
22
22
|
builderPluginAdapterBasic(),
|
23
23
|
builderPluginAdapterSSR(options),
|
@@ -1,9 +1,9 @@
|
|
1
1
|
async function createBuilderGenerator(bundler) {
|
2
2
|
if (bundler === "rspack") {
|
3
|
-
const { createRspackBuilderForModern } = await import("./builder-rspack");
|
3
|
+
const { createRspackBuilderForModern } = await import("./builder-rspack/index.js");
|
4
4
|
return createRspackBuilderForModern;
|
5
5
|
}
|
6
|
-
const { createWebpackBuilderForModern } = await import("./builder-webpack");
|
6
|
+
const { createWebpackBuilderForModern } = await import("./builder-webpack/index.js");
|
7
7
|
return createWebpackBuilderForModern;
|
8
8
|
}
|
9
9
|
export {
|
@@ -3,9 +3,7 @@ import { logger } from "@modern-js/utils";
|
|
3
3
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
4
4
|
import { generateRoutes } from "../utils/routes";
|
5
5
|
import { buildServerConfig } from "../utils/config";
|
6
|
-
import { registerCompiler } from "../utils/register";
|
7
6
|
const build = async (api, options) => {
|
8
|
-
var _resolvedConfig_source;
|
9
7
|
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
10
8
|
process.env.BUNDLE_ANALYZE = "true";
|
11
9
|
}
|
@@ -13,7 +11,6 @@ const build = async (api, options) => {
|
|
13
11
|
const appContext = api.useAppContext();
|
14
12
|
const hookRunners = api.useHookRunners();
|
15
13
|
await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);
|
16
|
-
await registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias);
|
17
14
|
const { apiOnly } = appContext;
|
18
15
|
if (apiOnly) {
|
19
16
|
const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
|
@@ -1,23 +1,27 @@
|
|
1
1
|
import path from "node:path";
|
2
2
|
import { ResolvedConfigContext } from "@modern-js/core";
|
3
|
-
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta
|
3
|
+
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } 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";
|
8
7
|
import { printInstructions } from "../utils/printInstructions";
|
9
8
|
import { setServer } from "../utils/createServer";
|
10
9
|
import { generateRoutes } from "../utils/routes";
|
11
10
|
import { buildServerConfig } from "../utils/config";
|
12
|
-
const dev = async (api, options, devServerOptions) => {
|
13
|
-
var _normalizedConfig_source, _normalizedConfig_tools
|
11
|
+
const dev = async (api, options, devServerOptions = {}) => {
|
12
|
+
var _normalizedConfig_source, _normalizedConfig_tools;
|
14
13
|
if (options.analyze) {
|
15
14
|
process.env.BUNDLE_ANALYZE = "true";
|
16
15
|
}
|
17
16
|
let normalizedConfig = api.useResolvedConfigContext();
|
18
17
|
const appContext = api.useAppContext();
|
19
18
|
const hookRunners = api.useHookRunners();
|
20
|
-
|
19
|
+
const { registerEsm } = await import("../esm/register-esm.mjs");
|
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
|
+
});
|
21
25
|
normalizedConfig = {
|
22
26
|
...normalizedConfig,
|
23
27
|
cliOptions: options
|
@@ -60,32 +64,20 @@ const dev = async (api, options, devServerOptions) => {
|
|
60
64
|
plugins: pluginInstances,
|
61
65
|
...devServerOptions
|
62
66
|
};
|
63
|
-
const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
64
67
|
if (apiOnly) {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
server.listen({
|
68
|
+
var _normalizedConfig_dev;
|
69
|
+
const app = await createDevServer(serverOptions, applyPlugins);
|
70
|
+
const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
71
|
+
app.listen({
|
70
72
|
port,
|
71
73
|
host
|
72
74
|
}, () => {
|
73
75
|
printInstructions(hookRunners, appContext, normalizedConfig);
|
74
76
|
});
|
75
77
|
} else {
|
76
|
-
const { server
|
77
|
-
|
78
|
-
|
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();
|
78
|
+
const { server } = await appContext.builder.startDevServer({
|
79
|
+
serverOptions,
|
80
|
+
applyPlugins
|
89
81
|
});
|
90
82
|
setServer(server);
|
91
83
|
}
|
@@ -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.js");
|
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.js");
|
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.js");
|
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.js");
|
58
58
|
await build(api);
|
59
59
|
}
|
60
|
-
const { deploy } = await import("./deploy");
|
60
|
+
const { deploy } = await import("./deploy.js");
|
61
61
|
await deploy(api, options);
|
62
62
|
process.exit(0);
|
63
63
|
});
|
@@ -72,7 +72,7 @@ const newCommand = (program, locale) => {
|
|
72
72
|
};
|
73
73
|
const inspectCommand = (program, api) => {
|
74
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");
|
75
|
+
const { inspect } = await import("./inspect.js");
|
76
76
|
inspect(api, options);
|
77
77
|
});
|
78
78
|
};
|
@@ -0,0 +1,39 @@
|
|
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
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
const import_meta = {};
|
2
|
+
import { register } from "node:module";
|
3
|
+
import path from "node:path";
|
4
|
+
const checkDep = async (dep) => {
|
5
|
+
try {
|
6
|
+
await import(dep);
|
7
|
+
return true;
|
8
|
+
} catch (error) {
|
9
|
+
return false;
|
10
|
+
}
|
11
|
+
};
|
12
|
+
const registerEsm = async ({ appDir, distDir, alias }) => {
|
13
|
+
const hasTsNode = await checkDep("ts-node");
|
14
|
+
if (hasTsNode) {
|
15
|
+
process.env.TS_NODE_TRANSPILE_ONLY = true;
|
16
|
+
process.env.TS_NODE_PROJECT = path.join(appDir, "tsconfig.json");
|
17
|
+
process.env.TS_NODE_SCOPE = true;
|
18
|
+
process.env.TS_NODE_FILES = true;
|
19
|
+
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(appDir, distDir)}/`;
|
20
|
+
register("./ts-node-loader.mjs", import_meta.url, {
|
21
|
+
data: {
|
22
|
+
appDir,
|
23
|
+
distDir,
|
24
|
+
alias
|
25
|
+
}
|
26
|
+
});
|
27
|
+
} else {
|
28
|
+
register("./esbuild-loader.mjs", import_meta.url, {
|
29
|
+
data: {
|
30
|
+
appDir,
|
31
|
+
distDir,
|
32
|
+
alias
|
33
|
+
}
|
34
|
+
});
|
35
|
+
}
|
36
|
+
};
|
37
|
+
export {
|
38
|
+
registerEsm
|
39
|
+
};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { pathToFileURL } from "url";
|
2
|
+
import { resolve as tsNodeResolve } from "ts-node/esm";
|
3
|
+
import * as tsConfigPaths from "@modern-js/utils/tsconfig-paths";
|
4
|
+
import { getAliasConfig } from "@modern-js/utils";
|
5
|
+
import path from "path";
|
6
|
+
console.log("ttttttttttttt", tsConfigPaths);
|
7
|
+
let matchPath;
|
8
|
+
function initialize({ appDir, alias }) {
|
9
|
+
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
10
|
+
const aliasConfig = getAliasConfig(alias, {
|
11
|
+
appDirectory: appDir,
|
12
|
+
tsconfigPath: path.resolve(appDir, TS_CONFIG_FILENAME)
|
13
|
+
});
|
14
|
+
const { paths = {}, absoluteBaseUrl = "./" } = aliasConfig;
|
15
|
+
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
16
|
+
let tsPath = paths[key];
|
17
|
+
if (typeof tsPath === "string" && path.isAbsolute(tsPath)) {
|
18
|
+
tsPath = path.relative(absoluteBaseUrl, tsPath);
|
19
|
+
}
|
20
|
+
if (typeof tsPath === "string") {
|
21
|
+
tsPath = [
|
22
|
+
tsPath
|
23
|
+
];
|
24
|
+
}
|
25
|
+
return {
|
26
|
+
...o,
|
27
|
+
[`${key}`]: tsPath
|
28
|
+
};
|
29
|
+
}, {});
|
30
|
+
matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
|
31
|
+
}
|
32
|
+
function resolve(specifier, context, defaultResolve) {
|
33
|
+
const match = matchPath(specifier);
|
34
|
+
return match ? tsNodeResolve(pathToFileURL(match).href, context, defaultResolve) : tsNodeResolve(specifier, context, defaultResolve);
|
35
|
+
}
|
36
|
+
import { transformSource, load } from "ts-node/esm";
|
37
|
+
export {
|
38
|
+
initialize,
|
39
|
+
load,
|
40
|
+
resolve,
|
41
|
+
transformSource
|
42
|
+
};
|
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 } from "@modern-js/utils";
|
3
|
+
import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE } 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,6 +47,7 @@ const appTools = (options = {
|
|
47
47
|
...appContext,
|
48
48
|
toolsType: "app-tools"
|
49
49
|
});
|
50
|
+
const nestedRoutes = {};
|
50
51
|
const locale = getLocaleLanguage();
|
51
52
|
i18n.changeLanguage({
|
52
53
|
locale
|
@@ -111,6 +112,21 @@ const appTools = (options = {
|
|
111
112
|
cleanRequireCache([
|
112
113
|
require.resolve("./plugins/analyze")
|
113
114
|
]);
|
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
|
+
};
|
114
130
|
}
|
115
131
|
};
|
116
132
|
}
|
@@ -7,6 +7,7 @@ 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";
|
10
11
|
const debug = createDebugger("plugin-analyze");
|
11
12
|
var analyze_default = ({ bundler }) => ({
|
12
13
|
name: "@modern-js/plugin-analyze",
|
@@ -44,9 +45,9 @@ var analyze_default = ({ bundler }) => ({
|
|
44
45
|
return;
|
45
46
|
}
|
46
47
|
const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
compatibleRequire(path.join(__dirname, "./getBundleEntry.js")),
|
49
|
+
compatibleRequire(path.join(__dirname, "./getServerRoutes.js")),
|
50
|
+
compatibleRequire(path.join(__dirname, "./getHtmlTemplate.js"))
|
50
51
|
]);
|
51
52
|
const { entrypoints } = await hookRunners.modifyEntrypoints({
|
52
53
|
entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
|
@@ -2,13 +2,12 @@ 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
|
5
|
+
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
|
6
6
|
const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
|
7
7
|
const base = "/";
|
8
8
|
const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
|
9
9
|
const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
|
10
10
|
const currentProjectModules = path.join(appDir, "node_modules");
|
11
|
-
const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
|
12
11
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
13
12
|
...fileTrace.reasons.entries()
|
14
13
|
].map(async ([_path, reasons]) => {
|
@@ -16,7 +15,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
16
15
|
return;
|
17
16
|
}
|
18
17
|
const filePath = await resolveTracedPath(base, _path);
|
19
|
-
if (
|
18
|
+
if (filePath.startsWith(serverRootDir) || filePath.startsWith(appDir) && !filePath.startsWith(currentProjectModules)) {
|
20
19
|
return;
|
21
20
|
}
|
22
21
|
if (!await isFile(filePath)) {
|
@@ -39,7 +38,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
39
38
|
const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
|
40
39
|
cwd: path.dirname(filePath)
|
41
40
|
});
|
42
|
-
if (packageJsonPath
|
41
|
+
if (packageJsonPath) {
|
43
42
|
const packageJson = await fse.readJSON(packageJsonPath);
|
44
43
|
pkgPath = baseDir = path.dirname(packageJsonPath);
|
45
44
|
subpath = path.relative(baseDir, filePath);
|
@@ -56,7 +55,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
56
55
|
path: filePath,
|
57
56
|
parents,
|
58
57
|
isDirectDep: parents.some((parent) => {
|
59
|
-
return
|
58
|
+
return parent.startsWith(appDir) && !parent.startsWith(currentProjectModules);
|
60
59
|
}),
|
61
60
|
subpath,
|
62
61
|
pkgName,
|
@@ -105,18 +105,10 @@ const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
|
|
105
105
|
});
|
106
106
|
};
|
107
107
|
const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
|
108
|
-
const isSubPath = (parentPath, childPath) => {
|
109
|
-
if (!parentPath || !childPath) {
|
110
|
-
return false;
|
111
|
-
}
|
112
|
-
const relative = path.relative(parentPath, childPath);
|
113
|
-
return relative && !relative.startsWith("..");
|
114
|
-
};
|
115
108
|
export {
|
116
109
|
findEntryFiles,
|
117
110
|
findPackageParents,
|
118
111
|
isFile,
|
119
|
-
isSubPath,
|
120
112
|
linkPackage,
|
121
113
|
readDirRecursive,
|
122
114
|
resolveTracedPath,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { IAppContext } from '@modern-js/core';
|
2
2
|
import type { AppNormalizedConfig } from '../../types';
|
3
3
|
export declare function getBuilderEnvironments(normalizedConfig: AppNormalizedConfig<'shared'>, appContext: IAppContext): {
|
4
|
-
[name: string]: import("@rsbuild/core
|
4
|
+
[name: string]: import("@rsbuild/core").EnvironmentConfig;
|
5
5
|
};
|
@@ -1 +1 @@
|
|
1
|
-
export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack").createRspackBuilderForModern>;
|
1
|
+
export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack/index.js").createRspackBuilderForModern>;
|
@@ -1,11 +1,20 @@
|
|
1
1
|
import type { PackageJson } from 'pkg-types';
|
2
|
+
import type { NodeFileTraceOptions } from '@vercel/nft';
|
2
3
|
import { traceFiles as defaultTraceFiles } from './utils';
|
3
|
-
export
|
4
|
+
export type { NodeFileTraceOptions } from '@vercel/nft';
|
5
|
+
export { nodeFileTrace } from '@vercel/nft';
|
6
|
+
export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions, }: {
|
4
7
|
appDir: string;
|
5
8
|
serverRootDir: string;
|
6
9
|
includeEntries: string[];
|
7
|
-
traceFiles?: ((entryFiles
|
10
|
+
traceFiles?: (({ entryFiles, serverRootDir, base, traceOptions, }: {
|
11
|
+
entryFiles: string[];
|
12
|
+
serverRootDir: string;
|
13
|
+
base?: string | undefined;
|
14
|
+
traceOptions?: NodeFileTraceOptions | undefined;
|
15
|
+
}) => Promise<import("@vercel/nft").NodeFileTraceResult>) | undefined;
|
8
16
|
entryFilter?: ((filePath: string) => boolean) | undefined;
|
9
17
|
modifyPackageJson?: ((pkgJson: PackageJson) => PackageJson) | undefined;
|
10
18
|
copyWholePackage?: ((pkgName: string) => boolean) | undefined;
|
19
|
+
traceOptions?: NodeFileTraceOptions | undefined;
|
11
20
|
}) => Promise<void>;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { PackageJson } from 'pkg-types';
|
2
|
+
import { NodeFileTraceOptions } from '@vercel/nft';
|
2
3
|
export type TracedPackage = {
|
3
4
|
name: string;
|
4
5
|
versions: Record<string, {
|
@@ -32,7 +33,12 @@ export declare const readDirRecursive: (dir: string, options?: ReadDirOptions) =
|
|
32
33
|
export declare const isFile: (file: string) => Promise<boolean>;
|
33
34
|
export declare const findEntryFiles: (rootDir: string, entryFilter?: ((filePath: string) => boolean) | undefined) => Promise<string[]>;
|
34
35
|
export declare const findPackageParents: (pkg: TracedPackage, version: string, tracedFiles: Record<string, TracedFile>) => string[];
|
35
|
-
export declare const traceFiles: (entryFiles
|
36
|
+
export declare const traceFiles: ({ entryFiles, serverRootDir, base, traceOptions, }: {
|
37
|
+
entryFiles: string[];
|
38
|
+
serverRootDir: string;
|
39
|
+
base?: string | undefined;
|
40
|
+
traceOptions?: NodeFileTraceOptions | undefined;
|
41
|
+
}) => Promise<import("@vercel/nft").NodeFileTraceResult>;
|
36
42
|
export declare const resolveTracedPath: (base: string, p: string) => Promise<string>;
|
37
43
|
export declare const isSubPath: (parentPath: string, childPath: string) => boolean | "";
|
38
44
|
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export default handler;
|
@@ -0,0 +1 @@
|
|
1
|
+
export { handler as default } from "./netlify-handler.cjs";
|
@@ -0,0 +1 @@
|
|
1
|
+
export function handler(request: any, context: any): Promise<any>;
|