@modern-js/app-tools 2.57.1-alpha.1 → 2.57.1-alpha.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ export async function initialize({ appDir, alias, tsconfigPath }) {
12
12
  }
13
13
 
14
14
  export function resolve(specifier, context, defaultResolve) {
15
- const match = matchPath(specifier, undefined, undefined, ['']);
15
+ const match = matchPath(specifier);
16
16
  return match
17
17
  ? tsNodeResolve(pathToFileURL(match).href, context, defaultResolve)
18
18
  : tsNodeResolve(specifier, context, defaultResolve);
@@ -1,7 +1,9 @@
1
1
  import path from 'path';
2
+ import { createRequire } from 'module';
2
3
  import tsConfigPaths from '@modern-js/utils/tsconfig-paths';
3
4
  import { getAliasConfig } from '@modern-js/utils';
4
5
 
6
+ const require = createRequire(import.meta.url);
5
7
  export function createMatchPath({ alias, appDir, tsconfigPath }) {
6
8
  const aliasConfig = getAliasConfig(alias, {
7
9
  appDirectory: appDir,
@@ -12,6 +14,19 @@ export function createMatchPath({ alias, appDir, tsconfigPath }) {
12
14
 
13
15
  const tsPaths = Object.keys(paths).reduce((o, key) => {
14
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
+
15
30
  if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
16
31
  tsPath = path.relative(absoluteBaseUrl, tsPath);
17
32
  }
@@ -1 +1,3 @@
1
1
  "use strict";
2
+ const { handler } = require("./netlify-handler");
3
+ module.exports.default = handler;
@@ -1,10 +1,28 @@
1
1
  "use strict";
2
- var import_index = require("./index.cjs");
3
- const requestHandler = null;
4
- (0, import_index.createHandler)();
5
- exports.handler = async (req, res) => {
6
- if (!requestHandler) {
7
- await (0, import_index.createHandler)();
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
8
15
  }
9
- return requestHandler(req, res);
16
+ return to;
10
17
  };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var netlify_entry_mjs_exports = {};
20
+ __export(netlify_entry_mjs_exports, {
21
+ handler: () => import_netlify_handler.handler
22
+ });
23
+ module.exports = __toCommonJS(netlify_entry_mjs_exports);
24
+ var import_netlify_handler = require("./netlify-handler");
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ handler
28
+ });
@@ -1,26 +1,4 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var netlifyEntry_exports = {};
20
- __export(netlifyEntry_exports, {
21
- createHandler: () => createHandler
22
- });
23
- module.exports = __toCommonJS(netlifyEntry_exports);
24
2
  const fs = require("node:fs/promises");
25
3
  const path = require("node:path");
26
4
  const { createNetlifyFunction } = require("@modern-js/prod-server/netlify");
@@ -75,13 +53,11 @@ async function createHandler() {
75
53
  return requestHandler;
76
54
  }
77
55
  createHandler();
78
- module.exports.default = async (request, context) => {
79
- if (!requestHandler) {
80
- await createHandler();
56
+ module.exports = {
57
+ handler: async (request, context) => {
58
+ if (!requestHandler) {
59
+ await createHandler();
60
+ }
61
+ return requestHandler(request, context);
81
62
  }
82
- return requestHandler(request, context);
83
63
  };
84
- // Annotate the CommonJS export names for ESM import in node:
85
- 0 && (module.exports = {
86
- createHandler
87
- });
@@ -56,6 +56,7 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
56
56
  const netlifyOutput = import_node_path.default.join(appDirectory, ".netlify");
57
57
  const funcsDirectory = import_node_path.default.join(netlifyOutput, "functions");
58
58
  const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
59
+ const handlerFilePath = import_node_path.default.join(funcsDirectory, "netlify-handler.js");
59
60
  return {
60
61
  async prepare() {
61
62
  await import_utils.fs.remove(netlifyOutput);
@@ -115,15 +116,14 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
115
116
  const pluginsCode = `[${plugins.map((plugin, index) => {
116
117
  return `plugin_${index}()`;
117
118
  }).join(",")}]`;
118
- let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlifyEntry.js"))).toString();
119
+ let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlify-handler.js"))).toString();
119
120
  const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
120
121
  entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
122
+ await import_utils.fs.writeFile(handlerFilePath, entryCode);
121
123
  if (isEsmProject) {
122
- const cjsEntryFilePath = import_node_path.default.join(funcsDirectory, "index.cjs");
123
- await import_utils.fs.writeFile(cjsEntryFilePath, entryCode);
124
- await import_utils.fs.writeFile(entryFilePath, `import('./index.cjs');`);
124
+ await import_utils.fs.copy(import_node_path.default.join(__dirname, "./netlify-entry-mjs.js"), entryFilePath);
125
125
  } else {
126
- await import_utils.fs.writeFile(entryFilePath, entryCode);
126
+ await import_utils.fs.copy(import_node_path.default.join(__dirname, "./netlify-entry-cjs.js"), entryFilePath);
127
127
  }
128
128
  },
129
129
  async end() {
@@ -52,6 +52,17 @@ const registerCompiler = async (appDir = process.cwd(), distDir, alias) => {
52
52
  const { paths = {}, absoluteBaseUrl = "./" } = aliasConfig;
53
53
  const tsPaths = Object.keys(paths).reduce((o, key) => {
54
54
  let tsPath = paths[key];
55
+ if (typeof tsPath === "string" && key.startsWith("@") && tsPath.startsWith("@")) {
56
+ try {
57
+ tsPath = require.resolve(tsPath, {
58
+ paths: [
59
+ process.cwd(),
60
+ ...module.paths
61
+ ]
62
+ });
63
+ } catch {
64
+ }
65
+ }
55
66
  if (typeof tsPath === "string" && import_node_path.default.isAbsolute(tsPath)) {
56
67
  tsPath = import_node_path.default.relative(absoluteBaseUrl, tsPath);
57
68
  }
@@ -0,0 +1,2 @@
1
+ export default handler;
2
+ import { handler } from "./netlify-handler";
@@ -1 +1 @@
1
- export {};
1
+ export { handler } from "./netlify-handler";
@@ -0,0 +1 @@
1
+ export function handler(request: any, context: any): Promise<any>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.57.1-alpha.1",
18
+ "version": "2.57.1-alpha.3",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -87,17 +87,17 @@
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.57.0",
91
90
  "@modern-js/node-bundle-require": "2.57.0",
91
+ "@modern-js/core": "2.57.0",
92
92
  "@modern-js/plugin": "2.57.0",
93
93
  "@modern-js/plugin-i18n": "2.57.0",
94
94
  "@modern-js/prod-server": "2.57.0",
95
95
  "@modern-js/rsbuild-plugin-esbuild": "2.57.0",
96
- "@modern-js/server": "2.57.0",
97
96
  "@modern-js/plugin-lint": "2.57.0",
97
+ "@modern-js/server": "2.57.0",
98
+ "@modern-js/types": "2.57.0",
98
99
  "@modern-js/server-core": "2.57.0",
99
100
  "@modern-js/server-utils": "2.57.0",
100
- "@modern-js/types": "2.57.0",
101
101
  "@modern-js/utils": "2.57.0",
102
102
  "@modern-js/uni-builder": "2.57.0",
103
103
  "@modern-js/plugin-data-loader": "2.57.0"
@@ -1 +0,0 @@
1
- export function createHandler(): Promise<any>;