@umijs/mfsu 4.0.0-rc.1 → 4.0.0-rc.4

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.
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -13,7 +13,7 @@ const isExternals_1 = require("./isExternals");
13
13
  const RE_NODE_MODULES = /node_modules/;
14
14
  const RE_UMI_LOCAL_DEV = /umi(-next)?\/packages\//;
15
15
  function isUmiLocalDev(path) {
16
- return RE_UMI_LOCAL_DEV.test(path);
16
+ return RE_UMI_LOCAL_DEV.test((0, utils_1.winPath)(path));
17
17
  }
18
18
  function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, }) {
19
19
  var _a, _b;
@@ -69,7 +69,7 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, })
69
69
  isMatch = !!(opts.exportAllMembers && value in opts.exportAllMembers);
70
70
  }
71
71
  if (isMatch) {
72
- replaceValue = `${remoteName}/${value}`;
72
+ replaceValue = `${remoteName}/${(0, utils_1.winPath)(value)}`;
73
73
  }
74
74
  // @ts-ignore
75
75
  const file = (path === null || path === void 0 ? void 0 : path.hub.file.opts.filename) || filename;
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAliasedPath = void 0;
4
- const path_1 = require("path");
5
4
  function getAliasedPath({ value, alias, }) {
6
5
  const importValue = value;
6
+ // equal alias
7
+ if (alias[value]) {
8
+ return alias[value];
9
+ }
7
10
  for (const key of Object.keys(alias)) {
8
11
  const aliasValue = alias[key];
9
12
  // exact alias
@@ -15,21 +18,13 @@ function getAliasedPath({ value, alias, }) {
15
18
  else
16
19
  continue;
17
20
  }
18
- // e.g. foo: path/to/foo
19
- if (importValue === key) {
20
- return aliasValue;
21
- }
22
21
  // e.g. foo: path/to/foo.js
23
- const slashedKey = isJSFile(aliasValue) ? key : addLastSlash(key);
24
- if (importValue.startsWith(slashedKey)) {
22
+ if (importValue.startsWith(addLastSlash(key))) {
25
23
  return importValue.replace(key, aliasValue);
26
24
  }
27
25
  }
28
26
  }
29
27
  exports.getAliasedPath = getAliasedPath;
30
- function isJSFile(path) {
31
- return ['.js', '.jsx', '.ts', '.tsx'].includes((0, path_1.extname)(path));
32
- }
33
28
  function addLastSlash(path) {
34
29
  return path.endsWith('/') ? path : `${path}/`;
35
30
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/dep/dep.js CHANGED
@@ -37,7 +37,7 @@ function resolve(context, path) {
37
37
  }
38
38
  class Dep {
39
39
  constructor(opts) {
40
- this.file = opts.file;
40
+ this.file = (0, utils_1.winPath)(opts.file);
41
41
  this.version = opts.version;
42
42
  this.cwd = opts.cwd;
43
43
  this.shortFile = this.file;
@@ -98,7 +98,7 @@ export * from '${this.file}';
98
98
  const dep = (0, path_1.isAbsolute)(opts.dep)
99
99
  ? opts.dep
100
100
  : (0, path_1.join)(opts.cwd, 'node_modules', opts.dep);
101
- const pkg = utils_1.pkgUp.sync({
101
+ const pkg = utils_1.pkgUp.pkgUpSync({
102
102
  cwd: dep,
103
103
  });
104
104
  (0, assert_1.default)(pkg, `package.json not found for ${opts.dep}`);
@@ -2,6 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getESBuildEntry = void 0;
4
4
  const constants_1 = require("../constants");
5
+ // from typescript `esModuleInterop`
6
+ const ES_INTEROP_FUNC = `__exportStar`;
7
+ const ES_INTEROP_HELPER = `
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var ${ES_INTEROP_FUNC} = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ `;
5
19
  function getESBuildEntry(opts) {
6
20
  return `
7
21
  (function() {
@@ -266,6 +280,7 @@ function getESBuildEntry(opts) {
266
280
  var __webpack_exports__ = {};
267
281
  (function() {
268
282
  var exports = __webpack_exports__;
283
+ ${ES_INTEROP_HELPER}
269
284
  var moduleMap = {
270
285
  ${opts.deps.map(getDepModuleStr).join(',\n')}
271
286
  };
@@ -299,15 +314,13 @@ ${opts.deps.map(getDepModuleStr).join(',\n')}
299
314
  `;
300
315
  }
301
316
  exports.getESBuildEntry = getESBuildEntry;
302
- function normalizeFile(file) {
303
- return file.replace(/\//g, '_');
304
- }
305
317
  function getDepModuleStr(dep) {
306
318
  return `
307
319
  "./${dep.file}": function() {
308
320
  return new Promise(resolve => {
309
- import('./${constants_1.MF_VA_PREFIX}${normalizeFile(dep.file)}.js').then(module => {
310
- resolve(() => module);
321
+ import('./${constants_1.MF_VA_PREFIX}${dep.normalizedFile}.js').then(module => {
322
+ module.default && ${ES_INTEROP_FUNC}(module, module.default);
323
+ resolve(() => module.default || module);
311
324
  });
312
325
  })
313
326
  }
@@ -0,0 +1,2 @@
1
+ import { IEsbuildLoaderHandlerParams } from '../types';
2
+ export declare function autoCssModulesHandler(opts: IEsbuildLoaderHandlerParams): string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.autoCssModulesHandler = void 0;
4
+ const utils_1 = require("@umijs/utils");
5
+ const CSS_MODULES_QUERY = '?modules';
6
+ const QUERY_LENGTH = CSS_MODULES_QUERY.length;
7
+ function autoCssModulesHandler(opts) {
8
+ let { code } = opts;
9
+ let offset = 0;
10
+ opts.imports.forEach((i) => {
11
+ if (i.d < 0 && (0, utils_1.isStyleFile)({ filename: i.n })) {
12
+ // import x from './index.less'
13
+ // => import x from '
14
+ const importSegment = code.substring(i.ss + offset, i.s + offset);
15
+ // is css module
16
+ if (~importSegment.indexOf(' from')) {
17
+ code = `${code.substring(0, i.e + offset)}${CSS_MODULES_QUERY}${code.substring(i.e + offset)}`;
18
+ offset += QUERY_LENGTH;
19
+ }
20
+ }
21
+ });
22
+ return code;
23
+ }
24
+ exports.autoCssModulesHandler = autoCssModulesHandler;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  function autoExportHandler(opts) {
4
4
  if (!opts.exports.length) {
5
- return `${opts.code};\nexport const __mfsu = 1;`;
5
+ return `${opts.code}\nexport const __mfsu = 1;`;
6
6
  }
7
7
  return opts.code;
8
8
  }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './constants';
2
+ export * from './esbuildHandlers/autoCssModules';
3
+ export { esbuildLoader } from './loader/esbuild';
2
4
  export * from './mfsu';
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,5 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.esbuildLoader = void 0;
13
18
  __exportStar(require("./constants"), exports);
19
+ __exportStar(require("./esbuildHandlers/autoCssModules"), exports);
20
+ // for independent use `esbuild-loader`
21
+ var esbuild_1 = require("./loader/esbuild");
22
+ Object.defineProperty(exports, "esbuildLoader", { enumerable: true, get: function () { return esbuild_1.esbuildLoader; } });
14
23
  __exportStar(require("./mfsu"), exports);
@@ -0,0 +1,5 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ import type { IEsbuildLoaderOpts } from '../types';
3
+ declare function esbuildTranspiler(this: LoaderContext<IEsbuildLoaderOpts>, source: string): Promise<void>;
4
+ export default esbuildTranspiler;
5
+ export declare const esbuildLoader: string;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.esbuildLoader = void 0;
24
+ const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
25
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
26
+ const path_1 = require("path");
27
+ function esbuildTranspiler(source) {
28
+ var _a;
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const done = this.async();
31
+ const options = this.getOptions();
32
+ const { handler = [], implementation } = options, otherOptions = __rest(options, ["handler", "implementation"]);
33
+ const transform = (implementation === null || implementation === void 0 ? void 0 : implementation.transform) || esbuild_1.transform;
34
+ const filePath = this.resourcePath;
35
+ const ext = (0, path_1.extname)(filePath).slice(1);
36
+ const transformOptions = Object.assign(Object.assign({}, otherOptions), { target: (_a = options.target) !== null && _a !== void 0 ? _a : 'es2015', loader: ext !== null && ext !== void 0 ? ext : 'js', sourcemap: this.sourceMap, sourcefile: filePath });
37
+ try {
38
+ let { code, map } = yield transform(source, transformOptions);
39
+ if (handler.length) {
40
+ yield es_module_lexer_1.init;
41
+ handler.forEach((handle) => {
42
+ const [imports, exports] = (0, es_module_lexer_1.parse)(code);
43
+ code = handle({ code, imports, exports, filePath });
44
+ });
45
+ }
46
+ done(null, code, map && JSON.parse(map));
47
+ }
48
+ catch (error) {
49
+ done(error);
50
+ }
51
+ });
52
+ }
53
+ exports.default = esbuildTranspiler;
54
+ exports.esbuildLoader = __filename;
package/dist/mfsu.js CHANGED
@@ -53,7 +53,7 @@ class MFSU {
53
53
  // swc don't support top-level await
54
54
  // ref: https://github.com/vercel/next.js/issues/31054
55
55
  asyncImport(content) {
56
- return `await import('${content}');`;
56
+ return `await import('${(0, utils_1.winPath)(content)}');`;
57
57
  // return `(async () => await import('${content}'))();`;
58
58
  }
59
59
  setWebpackConfig(opts) {
package/dist/types.d.ts CHANGED
@@ -1,4 +1,16 @@
1
+ import type { ImportSpecifier } from '@umijs/bundler-utils/compiled/es-module-lexer';
2
+ import type { TransformOptions } from '@umijs/bundler-utils/compiled/esbuild';
1
3
  export declare enum Mode {
2
4
  development = "development",
3
5
  production = "production"
4
6
  }
7
+ export interface IEsbuildLoaderHandlerParams {
8
+ code: string;
9
+ filePath: string;
10
+ imports: readonly ImportSpecifier[];
11
+ exports: readonly string[];
12
+ }
13
+ export interface IEsbuildLoaderOpts extends Partial<TransformOptions> {
14
+ handler?: Array<(opts: IEsbuildLoaderHandlerParams) => string>;
15
+ implementation?: typeof import('@umijs/bundler-utils/compiled/esbuild');
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.4",
4
4
  "description": "@umijs/mfsu",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/mfsu#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -21,15 +21,15 @@
21
21
  "dev": "pnpm build -- --watch"
22
22
  },
23
23
  "dependencies": {
24
- "@umijs/bundler-esbuild": "4.0.0-rc.1",
25
- "@umijs/bundler-utils": "4.0.0-rc.1",
26
- "@umijs/utils": "4.0.0-rc.1"
24
+ "@umijs/bundler-esbuild": "4.0.0-rc.4",
25
+ "@umijs/bundler-utils": "4.0.0-rc.4",
26
+ "@umijs/utils": "4.0.0-rc.4",
27
+ "enhanced-resolve": "5.9.1"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@types/express": "4.17.13",
30
- "enhanced-resolve": "5.8.3",
31
31
  "mrmime": "1.0.0",
32
- "webpack": "5.64.4",
32
+ "webpack": "5.69.1",
33
33
  "webpack-virtual-modules": "0.4.3"
34
34
  },
35
35
  "publishConfig": {