@modern-js/utils 2.22.1 → 2.23.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 2.23.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f08bbfc: feat(builder): add basic Vue 3 plugin
8
+
9
+ feat(builder): 增加基础的 Vue 3 插件
10
+
11
+ - a6b313a: fix(builder): can't use new React JSX with parent's package.json
12
+
13
+ fix(builder): 修复 package.json 在父级目录时无法使用新版 react jsx 的问题
14
+
15
+ - 8f2cab0: feat(builder): support using new URL to handle wasm assets
16
+
17
+ feat(builder): 支持通过 new URL 来处理 wasm 资源
18
+
19
+ ## 2.23.0
20
+
21
+ ### Patch Changes
22
+
23
+ - 7e6fb5f: chore: publishConfig add provenance config
24
+
25
+ chore: publishConfig 增加 provenance 配置
26
+
27
+ - a7a7ad7: chore: move some public code to the utils package
28
+ chore: 移动一些公共的代码到 utils 包
29
+ - 6dec7c2: test(utils): reuse the snapshot serializer of vitest config
30
+
31
+ test(utils): 复用 vitest 的 snapshot serializer
32
+
33
+ - c3216b5: chore: split the scheme into the plugin
34
+
35
+ chore: 拆分 scheme 到插件内部
36
+
3
37
  ## 2.22.1
4
38
 
5
39
  ### Patch Changes
@@ -39,10 +39,14 @@ const CHAIN_ID = {
39
39
  SVG: "svg",
40
40
  /** Rule for pug */
41
41
  PUG: "pug",
42
+ /** Rule for Vue */
43
+ VUE: "vue",
42
44
  /** Rule for toml */
43
45
  TOML: "toml",
44
46
  /** Rule for yaml */
45
47
  YAML: "yaml",
48
+ /** Rule for wasm */
49
+ WASM: "wasm",
46
50
  /** Rule for bff */
47
51
  JS_BFF_API: "js-bff-api"
48
52
  },
@@ -69,6 +73,8 @@ const CHAIN_ID = {
69
73
  URL: "url",
70
74
  /** pug-loader */
71
75
  PUG: "pug",
76
+ /** vue-loader */
77
+ VUE: "vue",
72
78
  /** file-loader */
73
79
  FILE: "file",
74
80
  /** @svgr/webpack */
@@ -138,12 +144,16 @@ const CHAIN_ID = {
138
144
  BUNDLE_ANALYZER: "bundle-analyze",
139
145
  /** BottomTemplatePlugin */
140
146
  BOTTOM_TEMPLATE: "bottom-template",
141
- /** HtmlCrossOriginPlugin */
142
- HTML_CROSS_ORIGIN: "html-cross-origin",
147
+ /** HtmlTagsPlugin */
148
+ HTML_TAGS: "html-tags",
143
149
  /** HtmlNoncePlugin */
144
150
  HTML_NONCE: "html-nonce",
151
+ /** HtmlCrossOriginPlugin */
152
+ HTML_CROSS_ORIGIN: "html-cross-origin",
145
153
  /** MiniCssExtractPlugin */
146
154
  MINI_CSS_EXTRACT: "mini-css-extract",
155
+ /** VueLoaderPlugin */
156
+ VUE_LOADER_PLUGIN: "vue-loader-plugin",
147
157
  /** ReactFastRefreshPlugin */
148
158
  REACT_FAST_REFRESH: "react-fast-refresh",
149
159
  /** ProvidePlugin for node polyfill */
@@ -157,9 +167,7 @@ const CHAIN_ID = {
157
167
  /** HtmlAsyncChunkPlugin */
158
168
  HTML_ASYNC_CHUNK: "html-async-chunk",
159
169
  /** SWC_POLYFILL_CHECKER */
160
- SWC_POLYFILL_CHECKER: "swc-polyfill-checker-plugin",
161
- /** HtmlTagsPlugin */
162
- HTML_TAGS: "html-tags"
170
+ SWC_POLYFILL_CHECKER: "swc-polyfill-checker-plugin"
163
171
  },
164
172
  /** Predefined minimizers */
165
173
  MINIMIZER: {
@@ -13,6 +13,9 @@ _export(exports, {
13
13
  ROUTE_SPEC_FILE: function() {
14
14
  return ROUTE_SPEC_FILE;
15
15
  },
16
+ NESTED_ROUTE_SPEC_FILE: function() {
17
+ return NESTED_ROUTE_SPEC_FILE;
18
+ },
16
19
  MAIN_ENTRY_NAME: function() {
17
20
  return MAIN_ENTRY_NAME;
18
21
  },
@@ -97,9 +100,6 @@ _export(exports, {
97
100
  INTERNAL_SERVER_PLUGINS: function() {
98
101
  return INTERNAL_SERVER_PLUGINS;
99
102
  },
100
- PLUGIN_SCHEMAS: function() {
101
- return PLUGIN_SCHEMAS;
102
- },
103
103
  DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS: function() {
104
104
  return DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS;
105
105
  }
@@ -107,6 +107,7 @@ _export(exports, {
107
107
  const _export_star = require("@swc/helpers/_/_export_star");
108
108
  _export_star._(require("./chainId"), exports);
109
109
  const ROUTE_SPEC_FILE = "route.json";
110
+ const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
110
111
  const MAIN_ENTRY_NAME = "main";
111
112
  const SERVER_BUNDLE_DIRECTORY = "bundles";
112
113
  const SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
@@ -153,8 +154,6 @@ const INTERNAL_MODULE_TOOLS_PLUGINS = {
153
154
  "@modern-js/plugin-testing": "@modern-js/plugin-testing/cli",
154
155
  "@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
155
156
  "@modern-js/plugin-tailwindcss": "@modern-js/plugin-tailwindcss/cli",
156
- // TODO: Maybe can remove it
157
- "@modern-js/plugin-nocode": "@modern-js/plugin-nocode/cli",
158
157
  // legacy router (inner react-router-dom v5)
159
158
  "@modern-js/plugin-router-legacy": "@modern-js/plugin-router-legacy/cli"
160
159
  };
@@ -185,8 +184,6 @@ const INTERNAL_CLI_PLUGINS = {
185
184
  "@modern-js/plugin-garfish": "@modern-js/plugin-garfish/cli",
186
185
  "@modern-js/plugin-tailwindcss": "@modern-js/plugin-tailwindcss/cli",
187
186
  "@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/cli",
188
- // TODO: Maybe can remove it
189
- "@modern-js/plugin-nocode": "@modern-js/plugin-nocode/cli",
190
187
  // legacy router (inner react-router-dom v5)
191
188
  "@modern-js/plugin-router-v5": "@modern-js/plugin-router-v5/cli"
192
189
  };
@@ -202,214 +199,6 @@ const INTERNAL_SERVER_PLUGINS = {
202
199
  [SERVER_PLUGIN_SERVER]: "@modern-js/plugin-server/server",
203
200
  [SERVER_PLUGIN_POLYFILL]: "@modern-js/plugin-polyfill/server"
204
201
  };
205
- const PLUGIN_SCHEMAS = {
206
- "@modern-js/runtime": [
207
- {
208
- target: "runtime",
209
- schema: {
210
- type: "object",
211
- additionalProperties: false
212
- }
213
- },
214
- {
215
- target: "runtimeByEntries",
216
- schema: {
217
- type: "object",
218
- patternProperties: {
219
- [ENTRY_NAME_PATTERN]: {
220
- type: "object"
221
- }
222
- },
223
- additionalProperties: false
224
- }
225
- }
226
- ],
227
- "@modern-js/plugin-swc": [
228
- {
229
- target: "tools.swc",
230
- schema: {
231
- typeof: [
232
- "object"
233
- ]
234
- }
235
- }
236
- ],
237
- "@modern-js/plugin-bff": [
238
- {
239
- target: "bff",
240
- schema: {
241
- type: "object",
242
- properties: {
243
- prefix: {
244
- type: [
245
- "string",
246
- "array"
247
- ],
248
- items: {
249
- type: "string"
250
- }
251
- },
252
- fetcher: {
253
- type: "string"
254
- },
255
- proxy: {
256
- type: "object"
257
- },
258
- requestCreator: {
259
- type: "string"
260
- }
261
- }
262
- }
263
- }
264
- ],
265
- "@modern-js/plugin-tailwindcss": [
266
- {
267
- target: "tools.tailwindcss",
268
- schema: {
269
- typeof: [
270
- "object",
271
- "function"
272
- ]
273
- }
274
- }
275
- ],
276
- "@modern-js/plugin-proxy": [
277
- {
278
- target: "dev.proxy",
279
- schema: {
280
- typeof: [
281
- "string",
282
- "object"
283
- ]
284
- }
285
- }
286
- ],
287
- "@modern-js/plugin-ssg": [
288
- {
289
- target: "output.ssg",
290
- schema: {
291
- oneOf: [
292
- {
293
- type: "boolean"
294
- },
295
- {
296
- type: "object"
297
- },
298
- {
299
- instanceof: "Function"
300
- }
301
- ]
302
- }
303
- }
304
- ],
305
- "@modern-js/plugin-state": [
306
- {
307
- target: "runtime.state",
308
- schema: {
309
- type: [
310
- "boolean",
311
- "object"
312
- ]
313
- }
314
- }
315
- ],
316
- "@modern-js/plugin-design-token": [
317
- // Legacy Features
318
- {
319
- target: "source.designSystem",
320
- schema: {
321
- typeof: [
322
- "object"
323
- ]
324
- }
325
- },
326
- {
327
- target: "source.designSystem.supportStyledComponents",
328
- schema: {
329
- type: [
330
- "boolean"
331
- ]
332
- }
333
- },
334
- {
335
- target: "designSystem",
336
- schema: {
337
- typeof: [
338
- "object"
339
- ]
340
- }
341
- }
342
- ],
343
- "@modern-js/plugin-router": [
344
- {
345
- target: "runtime.router",
346
- schema: {
347
- type: [
348
- "boolean",
349
- "object"
350
- ]
351
- }
352
- }
353
- ],
354
- "@modern-js/plugin-testing": [
355
- {
356
- target: "testing",
357
- schema: {
358
- typeof: [
359
- "object"
360
- ]
361
- }
362
- },
363
- {
364
- target: "tools.jest",
365
- schema: {
366
- typeof: [
367
- "object",
368
- "function"
369
- ]
370
- }
371
- }
372
- ],
373
- "@modern-js/plugin-garfish": [
374
- {
375
- target: "runtime.masterApp",
376
- schema: {
377
- type: [
378
- "boolean",
379
- "object"
380
- ]
381
- }
382
- },
383
- {
384
- target: "dev.withMasterApp",
385
- schema: {
386
- type: [
387
- "object"
388
- ]
389
- }
390
- },
391
- {
392
- target: "deploy.microFrontend",
393
- schema: {
394
- type: [
395
- "boolean",
396
- "object"
397
- ]
398
- }
399
- }
400
- ],
401
- "@modern-js/plugin-nocode": [],
402
- "@modern-js/plugin-worker": [
403
- {
404
- target: "deploy.worker.ssr",
405
- schema: {
406
- type: [
407
- "boolean"
408
- ]
409
- }
410
- }
411
- ]
412
- };
413
202
  const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
414
203
  allowNamespaces: true,
415
204
  allExtensions: true,
@@ -24,5 +24,4 @@ _export_star._(require("./print"), exports);
24
24
  _export_star._(require("./require"), exports);
25
25
  _export_star._(require("./routes"), exports);
26
26
  _export_star._(require("./runtimeExports"), exports);
27
- _export_star._(require("./test"), exports);
28
27
  _export_star._(require("./watch"), exports);
@@ -34,6 +34,7 @@ _export(exports, {
34
34
  });
35
35
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
36
36
  const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
37
+ const _pkgup = /* @__PURE__ */ _interop_require_default._(require("../../../compiled/pkg-up"));
37
38
  const _commands = require("../commands");
38
39
  const _compiled = require("../../compiled");
39
40
  const _common = require("../common");
@@ -59,19 +60,24 @@ const isPackageInstalled = (name, resolvePaths) => {
59
60
  return false;
60
61
  }
61
62
  };
62
- const isApiOnly = async (appDirectory, entryDir) => {
63
- const srcDir = _path.default.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : "src");
64
- const existSrc = await _compiled.fs.pathExists(srcDir);
63
+ const isApiOnly = async (appDirectory, entryDir, apiDir) => {
64
+ const existApi = await _compiled.fs.pathExists(apiDir !== null && apiDir !== void 0 ? apiDir : _path.default.join(appDirectory, "api"));
65
+ const existSrc = await _compiled.fs.pathExists(_path.default.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : "src"));
65
66
  const options = (0, _compiled.minimist)((0, _commands.getArgv)());
66
- return !existSrc || Boolean(options["api-only"]);
67
+ if (options["api-only"]) {
68
+ return true;
69
+ }
70
+ return existApi && !existSrc;
67
71
  };
68
72
  const isWebOnly = async () => {
69
73
  const options = (0, _compiled.minimist)((0, _commands.getArgv)());
70
74
  return Boolean(options["web-only"]);
71
75
  };
72
76
  const isBeyondReact17 = (cwd) => {
73
- const pkgPath = _path.default.join(cwd, "package.json");
74
- if (!_compiled.fs.existsSync(pkgPath)) {
77
+ const pkgPath = _pkgup.default.sync({
78
+ cwd
79
+ });
80
+ if (!pkgPath) {
75
81
  return false;
76
82
  }
77
83
  const pkgInfo = JSON.parse(_compiled.fs.readFileSync(pkgPath, "utf8"));
@@ -17,7 +17,6 @@ _export(exports, {
17
17
  return logger;
18
18
  }
19
19
  });
20
- const _define_property = require("@swc/helpers/_/_define_property");
21
20
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
22
21
  const _chalk = /* @__PURE__ */ _interop_require_default._(require("../../compiled/chalk"));
23
22
  const LOG_LEVEL = {
@@ -103,10 +102,6 @@ ${_chalk.default.grey(rest.join("\n"))}`;
103
102
  return longestLabel;
104
103
  }
105
104
  constructor(options = {}) {
106
- _define_property._(this, "level", void 0);
107
- _define_property._(this, "config", void 0);
108
- _define_property._(this, "types", void 0);
109
- _define_property._(this, "longestLabel", void 0);
110
105
  this.level = options.level || LOG_TYPES.log.level;
111
106
  this.config = {
112
107
  ...DEFAULT_CONFIG,
@@ -20,6 +20,8 @@ _export(exports, {
20
20
  return _serialize.serializeJson;
21
21
  }
22
22
  });
23
+ const _export_star = require("@swc/helpers/_/_export_star");
23
24
  const _storage = require("./storage");
24
25
  const _serialize = require("./serialize");
26
+ _export_star._(require("./nestedRoutes"), exports);
25
27
  const { run, useContext: useHeaders } = (0, _storage.createStorage)();
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "matchEntry", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return matchEntry;
9
+ }
10
+ });
11
+ function sortByUrlPath(entries) {
12
+ entries.sort(function(a, b) {
13
+ const length1 = a.urlPath.length;
14
+ const length2 = b.urlPath.length;
15
+ if (length1 < length2) {
16
+ return 1;
17
+ }
18
+ if (length1 > length2) {
19
+ return -1;
20
+ }
21
+ return 0;
22
+ });
23
+ return entries;
24
+ }
25
+ const matchEntry = (pathname, entries) => {
26
+ sortByUrlPath(entries);
27
+ return entries.find((entry) => pathname.startsWith(entry.urlPath));
28
+ };
@@ -15,7 +15,11 @@ _export(exports, {
15
15
  },
16
16
  HMR_SOCK_PATH: function() {
17
17
  return HMR_SOCK_PATH;
18
+ },
19
+ HTML_CHUNKSMAP_SEPARATOR: function() {
20
+ return HTML_CHUNKSMAP_SEPARATOR;
18
21
  }
19
22
  });
20
23
  const ROUTE_MANIFEST = `_MODERNJS_ROUTE_MANIFEST`;
21
24
  const HMR_SOCK_PATH = "/webpack-hmr";
25
+ const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
@@ -29,10 +29,14 @@ export const CHAIN_ID = {
29
29
  SVG: "svg",
30
30
  /** Rule for pug */
31
31
  PUG: "pug",
32
+ /** Rule for Vue */
33
+ VUE: "vue",
32
34
  /** Rule for toml */
33
35
  TOML: "toml",
34
36
  /** Rule for yaml */
35
37
  YAML: "yaml",
38
+ /** Rule for wasm */
39
+ WASM: "wasm",
36
40
  /** Rule for bff */
37
41
  JS_BFF_API: "js-bff-api"
38
42
  },
@@ -59,6 +63,8 @@ export const CHAIN_ID = {
59
63
  URL: "url",
60
64
  /** pug-loader */
61
65
  PUG: "pug",
66
+ /** vue-loader */
67
+ VUE: "vue",
62
68
  /** file-loader */
63
69
  FILE: "file",
64
70
  /** @svgr/webpack */
@@ -128,12 +134,16 @@ export const CHAIN_ID = {
128
134
  BUNDLE_ANALYZER: "bundle-analyze",
129
135
  /** BottomTemplatePlugin */
130
136
  BOTTOM_TEMPLATE: "bottom-template",
131
- /** HtmlCrossOriginPlugin */
132
- HTML_CROSS_ORIGIN: "html-cross-origin",
137
+ /** HtmlTagsPlugin */
138
+ HTML_TAGS: "html-tags",
133
139
  /** HtmlNoncePlugin */
134
140
  HTML_NONCE: "html-nonce",
141
+ /** HtmlCrossOriginPlugin */
142
+ HTML_CROSS_ORIGIN: "html-cross-origin",
135
143
  /** MiniCssExtractPlugin */
136
144
  MINI_CSS_EXTRACT: "mini-css-extract",
145
+ /** VueLoaderPlugin */
146
+ VUE_LOADER_PLUGIN: "vue-loader-plugin",
137
147
  /** ReactFastRefreshPlugin */
138
148
  REACT_FAST_REFRESH: "react-fast-refresh",
139
149
  /** ProvidePlugin for node polyfill */
@@ -147,9 +157,7 @@ export const CHAIN_ID = {
147
157
  /** HtmlAsyncChunkPlugin */
148
158
  HTML_ASYNC_CHUNK: "html-async-chunk",
149
159
  /** SWC_POLYFILL_CHECKER */
150
- SWC_POLYFILL_CHECKER: "swc-polyfill-checker-plugin",
151
- /** HtmlTagsPlugin */
152
- HTML_TAGS: "html-tags"
160
+ SWC_POLYFILL_CHECKER: "swc-polyfill-checker-plugin"
153
161
  },
154
162
  /** Predefined minimizers */
155
163
  MINIMIZER: {
@@ -1,4 +1,5 @@
1
1
  export const ROUTE_SPEC_FILE = "route.json";
2
+ export const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
2
3
  export const MAIN_ENTRY_NAME = "main";
3
4
  export const SERVER_BUNDLE_DIRECTORY = "bundles";
4
5
  export const SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
@@ -45,8 +46,6 @@ export const INTERNAL_MODULE_TOOLS_PLUGINS = {
45
46
  "@modern-js/plugin-testing": "@modern-js/plugin-testing/cli",
46
47
  "@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
47
48
  "@modern-js/plugin-tailwindcss": "@modern-js/plugin-tailwindcss/cli",
48
- // TODO: Maybe can remove it
49
- "@modern-js/plugin-nocode": "@modern-js/plugin-nocode/cli",
50
49
  // legacy router (inner react-router-dom v5)
51
50
  "@modern-js/plugin-router-legacy": "@modern-js/plugin-router-legacy/cli"
52
51
  };
@@ -77,8 +76,6 @@ export const INTERNAL_CLI_PLUGINS = {
77
76
  "@modern-js/plugin-garfish": "@modern-js/plugin-garfish/cli",
78
77
  "@modern-js/plugin-tailwindcss": "@modern-js/plugin-tailwindcss/cli",
79
78
  "@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/cli",
80
- // TODO: Maybe can remove it
81
- "@modern-js/plugin-nocode": "@modern-js/plugin-nocode/cli",
82
79
  // legacy router (inner react-router-dom v5)
83
80
  "@modern-js/plugin-router-v5": "@modern-js/plugin-router-v5/cli"
84
81
  };
@@ -94,214 +91,6 @@ export const INTERNAL_SERVER_PLUGINS = {
94
91
  [SERVER_PLUGIN_SERVER]: "@modern-js/plugin-server/server",
95
92
  [SERVER_PLUGIN_POLYFILL]: "@modern-js/plugin-polyfill/server"
96
93
  };
97
- export const PLUGIN_SCHEMAS = {
98
- "@modern-js/runtime": [
99
- {
100
- target: "runtime",
101
- schema: {
102
- type: "object",
103
- additionalProperties: false
104
- }
105
- },
106
- {
107
- target: "runtimeByEntries",
108
- schema: {
109
- type: "object",
110
- patternProperties: {
111
- [ENTRY_NAME_PATTERN]: {
112
- type: "object"
113
- }
114
- },
115
- additionalProperties: false
116
- }
117
- }
118
- ],
119
- "@modern-js/plugin-swc": [
120
- {
121
- target: "tools.swc",
122
- schema: {
123
- typeof: [
124
- "object"
125
- ]
126
- }
127
- }
128
- ],
129
- "@modern-js/plugin-bff": [
130
- {
131
- target: "bff",
132
- schema: {
133
- type: "object",
134
- properties: {
135
- prefix: {
136
- type: [
137
- "string",
138
- "array"
139
- ],
140
- items: {
141
- type: "string"
142
- }
143
- },
144
- fetcher: {
145
- type: "string"
146
- },
147
- proxy: {
148
- type: "object"
149
- },
150
- requestCreator: {
151
- type: "string"
152
- }
153
- }
154
- }
155
- }
156
- ],
157
- "@modern-js/plugin-tailwindcss": [
158
- {
159
- target: "tools.tailwindcss",
160
- schema: {
161
- typeof: [
162
- "object",
163
- "function"
164
- ]
165
- }
166
- }
167
- ],
168
- "@modern-js/plugin-proxy": [
169
- {
170
- target: "dev.proxy",
171
- schema: {
172
- typeof: [
173
- "string",
174
- "object"
175
- ]
176
- }
177
- }
178
- ],
179
- "@modern-js/plugin-ssg": [
180
- {
181
- target: "output.ssg",
182
- schema: {
183
- oneOf: [
184
- {
185
- type: "boolean"
186
- },
187
- {
188
- type: "object"
189
- },
190
- {
191
- instanceof: "Function"
192
- }
193
- ]
194
- }
195
- }
196
- ],
197
- "@modern-js/plugin-state": [
198
- {
199
- target: "runtime.state",
200
- schema: {
201
- type: [
202
- "boolean",
203
- "object"
204
- ]
205
- }
206
- }
207
- ],
208
- "@modern-js/plugin-design-token": [
209
- // Legacy Features
210
- {
211
- target: "source.designSystem",
212
- schema: {
213
- typeof: [
214
- "object"
215
- ]
216
- }
217
- },
218
- {
219
- target: "source.designSystem.supportStyledComponents",
220
- schema: {
221
- type: [
222
- "boolean"
223
- ]
224
- }
225
- },
226
- {
227
- target: "designSystem",
228
- schema: {
229
- typeof: [
230
- "object"
231
- ]
232
- }
233
- }
234
- ],
235
- "@modern-js/plugin-router": [
236
- {
237
- target: "runtime.router",
238
- schema: {
239
- type: [
240
- "boolean",
241
- "object"
242
- ]
243
- }
244
- }
245
- ],
246
- "@modern-js/plugin-testing": [
247
- {
248
- target: "testing",
249
- schema: {
250
- typeof: [
251
- "object"
252
- ]
253
- }
254
- },
255
- {
256
- target: "tools.jest",
257
- schema: {
258
- typeof: [
259
- "object",
260
- "function"
261
- ]
262
- }
263
- }
264
- ],
265
- "@modern-js/plugin-garfish": [
266
- {
267
- target: "runtime.masterApp",
268
- schema: {
269
- type: [
270
- "boolean",
271
- "object"
272
- ]
273
- }
274
- },
275
- {
276
- target: "dev.withMasterApp",
277
- schema: {
278
- type: [
279
- "object"
280
- ]
281
- }
282
- },
283
- {
284
- target: "deploy.microFrontend",
285
- schema: {
286
- type: [
287
- "boolean",
288
- "object"
289
- ]
290
- }
291
- }
292
- ],
293
- "@modern-js/plugin-nocode": [],
294
- "@modern-js/plugin-worker": [
295
- {
296
- target: "deploy.worker.ssr",
297
- schema: {
298
- type: [
299
- "boolean"
300
- ]
301
- }
302
- }
303
- ]
304
- };
305
94
  export const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
306
95
  allowNamespaces: true,
307
96
  allExtensions: true,
@@ -19,5 +19,4 @@ export * from "./print";
19
19
  export * from "./require";
20
20
  export * from "./routes";
21
21
  export * from "./runtimeExports";
22
- export * from "./test";
23
22
  export * from "./watch";
@@ -1,4 +1,5 @@
1
1
  import path from "path";
2
+ import pkgUp from "../../../compiled/pkg-up";
2
3
  import { getArgv } from "../commands";
3
4
  import { fs, minimist, semver } from "../../compiled";
4
5
  import { createDebugger } from "../common";
@@ -24,19 +25,24 @@ export const isPackageInstalled = (name, resolvePaths) => {
24
25
  return false;
25
26
  }
26
27
  };
27
- export const isApiOnly = async (appDirectory, entryDir) => {
28
- const srcDir = path.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : "src");
29
- const existSrc = await fs.pathExists(srcDir);
28
+ export const isApiOnly = async (appDirectory, entryDir, apiDir) => {
29
+ const existApi = await fs.pathExists(apiDir !== null && apiDir !== void 0 ? apiDir : path.join(appDirectory, "api"));
30
+ const existSrc = await fs.pathExists(path.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : "src"));
30
31
  const options = minimist(getArgv());
31
- return !existSrc || Boolean(options["api-only"]);
32
+ if (options["api-only"]) {
33
+ return true;
34
+ }
35
+ return existApi && !existSrc;
32
36
  };
33
37
  export const isWebOnly = async () => {
34
38
  const options = minimist(getArgv());
35
39
  return Boolean(options["web-only"]);
36
40
  };
37
41
  export const isBeyondReact17 = (cwd) => {
38
- const pkgPath = path.join(cwd, "package.json");
39
- if (!fs.existsSync(pkgPath)) {
42
+ const pkgPath = pkgUp.sync({
43
+ cwd
44
+ });
45
+ if (!pkgPath) {
40
46
  return false;
41
47
  }
42
48
  const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
@@ -1,4 +1,3 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
1
  import chalk from "../../compiled/chalk";
3
2
  const LOG_LEVEL = {
4
3
  error: 0,
@@ -83,10 +82,6 @@ ${chalk.grey(rest.join("\n"))}`;
83
82
  return longestLabel;
84
83
  }
85
84
  constructor(options = {}) {
86
- _define_property(this, "level", void 0);
87
- _define_property(this, "config", void 0);
88
- _define_property(this, "types", void 0);
89
- _define_property(this, "longestLabel", void 0);
90
85
  this.level = options.level || LOG_TYPES.log.level;
91
86
  this.config = {
92
87
  ...DEFAULT_CONFIG,
@@ -2,3 +2,4 @@ import { createStorage } from "./storage";
2
2
  const { run, useContext: useHeaders } = createStorage();
3
3
  export { run, useHeaders };
4
4
  export { serializeJson } from "./serialize";
5
+ export * from "./nestedRoutes";
@@ -0,0 +1,18 @@
1
+ function sortByUrlPath(entries) {
2
+ entries.sort(function(a, b) {
3
+ const length1 = a.urlPath.length;
4
+ const length2 = b.urlPath.length;
5
+ if (length1 < length2) {
6
+ return 1;
7
+ }
8
+ if (length1 > length2) {
9
+ return -1;
10
+ }
11
+ return 0;
12
+ });
13
+ return entries;
14
+ }
15
+ export const matchEntry = (pathname, entries) => {
16
+ sortByUrlPath(entries);
17
+ return entries.find((entry) => pathname.startsWith(entry.urlPath));
18
+ };
@@ -1,2 +1,3 @@
1
1
  export const ROUTE_MANIFEST = `_MODERNJS_ROUTE_MANIFEST`;
2
2
  export const HMR_SOCK_PATH = "/webpack-hmr";
3
+ export const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
@@ -29,10 +29,14 @@ export declare const CHAIN_ID: {
29
29
  readonly SVG: "svg";
30
30
  /** Rule for pug */
31
31
  readonly PUG: "pug";
32
+ /** Rule for Vue */
33
+ readonly VUE: "vue";
32
34
  /** Rule for toml */
33
35
  readonly TOML: "toml";
34
36
  /** Rule for yaml */
35
37
  readonly YAML: "yaml";
38
+ /** Rule for wasm */
39
+ readonly WASM: "wasm";
36
40
  /** Rule for bff */
37
41
  readonly JS_BFF_API: "js-bff-api";
38
42
  };
@@ -59,6 +63,8 @@ export declare const CHAIN_ID: {
59
63
  readonly URL: "url";
60
64
  /** pug-loader */
61
65
  readonly PUG: "pug";
66
+ /** vue-loader */
67
+ readonly VUE: "vue";
62
68
  /** file-loader */
63
69
  readonly FILE: "file";
64
70
  /** @svgr/webpack */
@@ -128,12 +134,16 @@ export declare const CHAIN_ID: {
128
134
  readonly BUNDLE_ANALYZER: "bundle-analyze";
129
135
  /** BottomTemplatePlugin */
130
136
  readonly BOTTOM_TEMPLATE: "bottom-template";
131
- /** HtmlCrossOriginPlugin */
132
- readonly HTML_CROSS_ORIGIN: "html-cross-origin";
137
+ /** HtmlTagsPlugin */
138
+ readonly HTML_TAGS: "html-tags";
133
139
  /** HtmlNoncePlugin */
134
140
  readonly HTML_NONCE: "html-nonce";
141
+ /** HtmlCrossOriginPlugin */
142
+ readonly HTML_CROSS_ORIGIN: "html-cross-origin";
135
143
  /** MiniCssExtractPlugin */
136
144
  readonly MINI_CSS_EXTRACT: "mini-css-extract";
145
+ /** VueLoaderPlugin */
146
+ readonly VUE_LOADER_PLUGIN: "vue-loader-plugin";
137
147
  /** ReactFastRefreshPlugin */
138
148
  readonly REACT_FAST_REFRESH: "react-fast-refresh";
139
149
  /** ProvidePlugin for node polyfill */
@@ -148,8 +158,6 @@ export declare const CHAIN_ID: {
148
158
  readonly HTML_ASYNC_CHUNK: "html-async-chunk";
149
159
  /** SWC_POLYFILL_CHECKER */
150
160
  readonly SWC_POLYFILL_CHECKER: "swc-polyfill-checker-plugin";
151
- /** HtmlTagsPlugin */
152
- readonly HTML_TAGS: "html-tags";
153
161
  };
154
162
  /** Predefined minimizers */
155
163
  readonly MINIMIZER: {
@@ -3,6 +3,10 @@ import { InternalPlugins } from '@modern-js/types';
3
3
  * route specification file
4
4
  */
5
5
  export declare const ROUTE_SPEC_FILE = "route.json";
6
+ /**
7
+ * Front-end routing metadata
8
+ */
9
+ export declare const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
6
10
  /**
7
11
  * main entry name
8
12
  */
@@ -85,127 +89,6 @@ export declare const SERVER_PLUGIN_KOA = "@modern-js/plugin-koa";
85
89
  export declare const SERVER_PLUGIN_SERVER = "@modern-js/plugin-server";
86
90
  export declare const SERVER_PLUGIN_POLYFILL = "@modern-js/plugin-polyfill";
87
91
  export declare const INTERNAL_SERVER_PLUGINS: InternalPlugins;
88
- /**
89
- * The schema registered in the plugin.
90
- */
91
- export declare const PLUGIN_SCHEMAS: {
92
- '@modern-js/runtime': ({
93
- target: string;
94
- schema: {
95
- type: string;
96
- additionalProperties: boolean;
97
- patternProperties?: undefined;
98
- };
99
- } | {
100
- target: string;
101
- schema: {
102
- type: string;
103
- patternProperties: {
104
- "^[a-zA-Z0-9_-]+$": {
105
- type: string;
106
- };
107
- };
108
- additionalProperties: boolean;
109
- };
110
- })[];
111
- '@modern-js/plugin-swc': {
112
- target: string;
113
- schema: {
114
- typeof: string[];
115
- };
116
- }[];
117
- '@modern-js/plugin-bff': {
118
- target: string;
119
- schema: {
120
- type: string;
121
- properties: {
122
- prefix: {
123
- type: string[];
124
- items: {
125
- type: string;
126
- };
127
- };
128
- fetcher: {
129
- type: string;
130
- };
131
- proxy: {
132
- type: string;
133
- };
134
- requestCreator: {
135
- type: string;
136
- };
137
- };
138
- };
139
- }[];
140
- '@modern-js/plugin-tailwindcss': {
141
- target: string;
142
- schema: {
143
- typeof: string[];
144
- };
145
- }[];
146
- '@modern-js/plugin-proxy': {
147
- target: string;
148
- schema: {
149
- typeof: string[];
150
- };
151
- }[];
152
- '@modern-js/plugin-ssg': {
153
- target: string;
154
- schema: {
155
- oneOf: ({
156
- type: string;
157
- instanceof?: undefined;
158
- } | {
159
- instanceof: string;
160
- type?: undefined;
161
- })[];
162
- };
163
- }[];
164
- '@modern-js/plugin-state': {
165
- target: string;
166
- schema: {
167
- type: string[];
168
- };
169
- }[];
170
- '@modern-js/plugin-design-token': ({
171
- target: string;
172
- schema: {
173
- typeof: string[];
174
- type?: undefined;
175
- };
176
- } | {
177
- target: string;
178
- schema: {
179
- type: string[];
180
- typeof?: undefined;
181
- };
182
- })[];
183
- '@modern-js/plugin-router': {
184
- target: string;
185
- schema: {
186
- type: string[];
187
- };
188
- }[];
189
- '@modern-js/plugin-testing': {
190
- target: string;
191
- schema: {
192
- typeof: string[];
193
- };
194
- }[];
195
- '@modern-js/plugin-garfish': {
196
- target: string;
197
- schema: {
198
- type: string[];
199
- };
200
- }[];
201
- '@modern-js/plugin-nocode': never[];
202
- '@modern-js/plugin-worker': {
203
- target: string;
204
- schema: {
205
- type: string[];
206
- };
207
- }[];
208
- };
209
92
  /**
210
93
  * The `@babel/preset-typescript` default options.
211
94
  *
@@ -19,5 +19,4 @@ export * from './print';
19
19
  export * from './require';
20
20
  export * from './routes';
21
21
  export * from './runtimeExports';
22
- export * from './test';
23
22
  export * from './watch';
@@ -10,7 +10,17 @@ export declare const isDepExists: (appDirectory: string, name: string) => boolea
10
10
  * Try to resolve npm package, return true if package is installed.
11
11
  */
12
12
  export declare const isPackageInstalled: (name: string, resolvePaths: string | string[]) => boolean;
13
- export declare const isApiOnly: (appDirectory: string, entryDir?: string) => Promise<boolean>;
13
+ /**
14
+ * Check is api only project
15
+ * 1. env --api-only
16
+ * 2. exist ${apiDir}/ && not exist ${entryDir}/
17
+ *
18
+ * @param appDirectory
19
+ * @param entryDir default 'src'
20
+ * @param apiDir default 'api'
21
+ * @returns boolean
22
+ */
23
+ export declare const isApiOnly: (appDirectory: string, entryDir?: string, apiDir?: string) => Promise<boolean>;
14
24
  export declare const isWebOnly: () => Promise<boolean>;
15
25
  export declare const isBeyondReact17: (cwd: string) => boolean;
16
26
  export declare const isReact18: (cwd: string) => boolean;
@@ -5,4 +5,5 @@
5
5
  import type { IncomingHttpHeaders } from 'http';
6
6
  declare const run: <O>(context: IncomingHttpHeaders, cb: () => O | Promise<O>) => Promise<O>, useHeaders: () => IncomingHttpHeaders;
7
7
  export { run, useHeaders };
8
- export { serializeJson } from './serialize';
8
+ export { serializeJson } from './serialize';
9
+ export * from './nestedRoutes';
@@ -0,0 +1,3 @@
1
+ import type { ModernServerContext, ServerRoute } from '@modern-js/types';
2
+ export type ServerContext = Pick<ModernServerContext, 'logger' | 'req' | 'res' | 'params' | 'headers' | 'method' | 'url' | 'host' | 'protocol' | 'origin' | 'href' | 'path' | 'query'>;
3
+ export declare const matchEntry: (pathname: string, entries: ServerRoute[]) => ServerRoute | undefined;
@@ -5,4 +5,8 @@ export declare const ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
5
5
  /**
6
6
  * hmr socket connect path
7
7
  */
8
- export declare const HMR_SOCK_PATH = "/webpack-hmr";
8
+ export declare const HMR_SOCK_PATH = "/webpack-hmr";
9
+ /**
10
+ * html placeholder
11
+ */
12
+ export declare const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.22.1",
18
+ "version": "2.23.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -36,6 +36,7 @@
36
36
  },
37
37
  "./runtime/router": {
38
38
  "types": "./dist/types/runtime/router.d.ts",
39
+ "require": "./dist/cjs/runtime/router.js",
39
40
  "default": "./dist/esm/runtime/router.js"
40
41
  },
41
42
  "./runtime/remix-router": {
@@ -52,10 +53,12 @@
52
53
  },
53
54
  "./runtime-node": {
54
55
  "types": "./dist/types/runtime-node/index.d.ts",
56
+ "require": "./dist/cjs/runtime-node/index.js",
55
57
  "default": "./dist/esm/runtime-node/index.js"
56
58
  },
57
59
  "./runtime-node/router": {
58
60
  "types": "./dist/types/runtime-node/router.d.ts",
61
+ "require": "./dist/cjs/runtime-node/router.js",
59
62
  "default": "./dist/esm/runtime-node/router.js"
60
63
  },
61
64
  "./universal/constants": {
@@ -97,7 +100,8 @@
97
100
  },
98
101
  "publishConfig": {
99
102
  "registry": "https://registry.npmjs.org/",
100
- "access": "public"
103
+ "access": "public",
104
+ "provenance": true
101
105
  },
102
106
  "typesVersions": {
103
107
  "*": {
@@ -231,9 +235,9 @@
231
235
  "typescript": "^5",
232
236
  "webpack": "^5.82.1",
233
237
  "@types/serialize-javascript": "^5.0.1",
234
- "@modern-js/types": "2.22.1",
235
- "@scripts/build": "2.22.1",
236
- "@scripts/jest-config": "2.22.1"
238
+ "@modern-js/types": "2.23.1",
239
+ "@scripts/build": "2.23.1",
240
+ "@scripts/jest-config": "2.23.1"
237
241
  },
238
242
  "sideEffects": false,
239
243
  "scripts": {
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "initSnapshotSerializer", {
6
- enumerable: true,
7
- get: function() {
8
- return initSnapshotSerializer;
9
- }
10
- });
11
- const initSnapshotSerializer = (root) => {
12
- expect.addSnapshotSerializer({
13
- test: (val) => typeof val === "string" && (val.includes("modern.js") || val.includes("node_modules") || val.includes(root)),
14
- print: (val) => (
15
- // eslint-disable-next-line no-nested-ternary
16
- typeof val === "string" ? val.includes("node_modules") ? `"${val.replace(/.+node_modules/, ``).replace(/\\/g, "/")}"` : val.includes("modern.js") ? `"${val.replace(/.+modern\.js/, ``).replace(/\\/g, "/")}"` : `"${val.replace(root, "").replace(/\\/g, "/")}"` : val
17
- )
18
- });
19
- };
@@ -1,9 +0,0 @@
1
- export const initSnapshotSerializer = (root) => {
2
- expect.addSnapshotSerializer({
3
- test: (val) => typeof val === "string" && (val.includes("modern.js") || val.includes("node_modules") || val.includes(root)),
4
- print: (val) => (
5
- // eslint-disable-next-line no-nested-ternary
6
- typeof val === "string" ? val.includes("node_modules") ? `"${val.replace(/.+node_modules/, ``).replace(/\\/g, "/")}"` : val.includes("modern.js") ? `"${val.replace(/.+modern\.js/, ``).replace(/\\/g, "/")}"` : `"${val.replace(root, "").replace(/\\/g, "/")}"` : val
7
- )
8
- });
9
- };
@@ -1,5 +0,0 @@
1
- /**
2
- *
3
- * remove the path before "modern.js"
4
- */
5
- export declare const initSnapshotSerializer: (root: string) => void;