@umijs/mfsu 4.0.0-canary.20220428.1 → 4.0.0-canary.20220429.2

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.
Files changed (55) hide show
  1. package/package.json +4 -4
  2. package/dist/babelPlugins/awaitImport/awaitImport.d.ts +0 -27
  3. package/dist/babelPlugins/awaitImport/awaitImport.js +0 -120
  4. package/dist/babelPlugins/awaitImport/checkMatch.d.ts +0 -18
  5. package/dist/babelPlugins/awaitImport/checkMatch.js +0 -127
  6. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +0 -4
  7. package/dist/babelPlugins/awaitImport/getAliasedPath.js +0 -30
  8. package/dist/babelPlugins/awaitImport/getRealPath.d.ts +0 -4
  9. package/dist/babelPlugins/awaitImport/getRealPath.js +0 -24
  10. package/dist/babelPlugins/awaitImport/isExternals.d.ts +0 -11
  11. package/dist/babelPlugins/awaitImport/isExternals.js +0 -29
  12. package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts +0 -1
  13. package/dist/babelPlugins/awaitImport/parseSpecifiers.js +0 -55
  14. package/dist/constants.d.ts +0 -7
  15. package/dist/constants.js +0 -10
  16. package/dist/dep/dep.d.ts +0 -30
  17. package/dist/dep/dep.js +0 -107
  18. package/dist/dep/getCJSExports.d.ts +0 -3
  19. package/dist/dep/getCJSExports.js +0 -58
  20. package/dist/dep/getExposeFromContent.d.ts +0 -6
  21. package/dist/dep/getExposeFromContent.js +0 -80
  22. package/dist/dep/getModuleExports.d.ts +0 -7
  23. package/dist/dep/getModuleExports.js +0 -45
  24. package/dist/depBuilder/depBuilder.d.ts +0 -30
  25. package/dist/depBuilder/depBuilder.js +0 -173
  26. package/dist/depBuilder/getESBuildEntry.d.ts +0 -4
  27. package/dist/depBuilder/getESBuildEntry.js +0 -328
  28. package/dist/depInfo.d.ts +0 -17
  29. package/dist/depInfo.js +0 -50
  30. package/dist/esbuildHandlers/autoCssModules.d.ts +0 -2
  31. package/dist/esbuildHandlers/autoCssModules.js +0 -24
  32. package/dist/esbuildHandlers/awaitImport/index.d.ts +0 -12
  33. package/dist/esbuildHandlers/awaitImport/index.js +0 -44
  34. package/dist/index.d.ts +0 -4
  35. package/dist/index.js +0 -23
  36. package/dist/loader/esbuild.d.ts +0 -5
  37. package/dist/loader/esbuild.js +0 -54
  38. package/dist/mfsu.d.ts +0 -63
  39. package/dist/mfsu.js +0 -304
  40. package/dist/moduleGraph.d.ts +0 -73
  41. package/dist/moduleGraph.js +0 -197
  42. package/dist/types.d.ts +0 -16
  43. package/dist/types.js +0 -8
  44. package/dist/utils/makeArray.d.ts +0 -1
  45. package/dist/utils/makeArray.js +0 -7
  46. package/dist/utils/trimFileContent.d.ts +0 -1
  47. package/dist/utils/trimFileContent.js +0 -7
  48. package/dist/webpackPlugins/buildDepPlugin.d.ts +0 -10
  49. package/dist/webpackPlugins/buildDepPlugin.js +0 -17
  50. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +0 -5
  51. package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +0 -19
  52. package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts +0 -10
  53. package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +0 -28
  54. package/dist/webpackPlugins/writeCachePlugin.d.ts +0 -10
  55. package/dist/webpackPlugins/writeCachePlugin.js +0 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.0-canary.20220428.1",
3
+ "version": "4.0.0-canary.20220429.2",
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",
@@ -22,9 +22,9 @@
22
22
  "test": "umi-scripts jest-turbo"
23
23
  },
24
24
  "dependencies": {
25
- "@umijs/bundler-esbuild": "4.0.0-canary.20220428.1",
26
- "@umijs/bundler-utils": "4.0.0-canary.20220428.1",
27
- "@umijs/utils": "4.0.0-canary.20220428.1",
25
+ "@umijs/bundler-esbuild": "4.0.0-canary.20220429.2",
26
+ "@umijs/bundler-utils": "4.0.0-canary.20220429.2",
27
+ "@umijs/utils": "4.0.0-canary.20220429.2",
28
28
  "enhanced-resolve": "5.9.2"
29
29
  },
30
30
  "devDependencies": {
@@ -1,27 +0,0 @@
1
- import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
2
- import * as t from '@umijs/bundler-utils/compiled/babel/types';
3
- export interface IOpts {
4
- onTransformDeps?: Function;
5
- onCollect?: Function;
6
- exportAllMembers?: Record<string, string[]>;
7
- unMatchLibs?: string[];
8
- remoteName?: string;
9
- alias?: Record<string, string>;
10
- externals?: any;
11
- }
12
- export default function (): {
13
- pre(): void;
14
- post(state: any): void;
15
- visitor: {
16
- Program: {
17
- exit(path: Babel.NodePath<t.Program>, { opts }: {
18
- opts: IOpts;
19
- }): void;
20
- };
21
- CallExpression: {
22
- exit(path: Babel.NodePath<t.CallExpression>, { opts }: {
23
- opts: IOpts;
24
- }): void;
25
- };
26
- };
27
- };
@@ -1,120 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = 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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
27
- const checkMatch_1 = require("./checkMatch");
28
- function default_1() {
29
- return {
30
- pre() {
31
- // @ts-ignore
32
- this.cache = new Map();
33
- },
34
- post(state) {
35
- var _a, _b;
36
- // @ts-ignore
37
- const { cache } = this;
38
- if (cache.has(state.opts.filename)) {
39
- // @ts-ignore
40
- (_b = (_a = this.opts).onCollect) === null || _b === void 0 ? void 0 : _b.call(_a, {
41
- file: state.opts.filename,
42
- data: cache.get(state.opts.filename),
43
- });
44
- }
45
- },
46
- visitor: {
47
- Program: {
48
- exit(path, { opts }) {
49
- let index = path.node.body.length - 1;
50
- while (index >= 0) {
51
- const node = path.node.body[index];
52
- // import x from 'x';
53
- // import * as x from 'x';
54
- // import x, * as xx from 'x';
55
- // import { x } from 'x';
56
- if (t.isImportDeclaration(node)) {
57
- const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
58
- // @ts-ignore
59
- cache: this.cache,
60
- value: node.source.value,
61
- opts,
62
- path,
63
- });
64
- if (isMatch) {
65
- node.source.value = replaceValue;
66
- }
67
- }
68
- // export * from 'x';
69
- else if (t.isExportAllDeclaration(node)) {
70
- const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
71
- // @ts-ignore
72
- cache: this.cache,
73
- value: node.source.value,
74
- opts,
75
- path,
76
- });
77
- if (isMatch) {
78
- node.source.value = replaceValue;
79
- }
80
- }
81
- // export { x } from 'x';
82
- else if (t.isExportNamedDeclaration(node) && node.source) {
83
- const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
84
- // @ts-ignore
85
- cache: this.cache,
86
- value: node.source.value,
87
- opts,
88
- path,
89
- });
90
- if (isMatch) {
91
- node.source.value = replaceValue;
92
- }
93
- }
94
- index -= 1;
95
- }
96
- },
97
- },
98
- CallExpression: {
99
- exit(path, { opts }) {
100
- const { node } = path;
101
- if (t.isImport(node.callee) &&
102
- node.arguments.length === 1 &&
103
- node.arguments[0].type === 'StringLiteral') {
104
- const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
105
- // @ts-ignore
106
- cache: this.cache,
107
- value: node.arguments[0].value,
108
- opts,
109
- path,
110
- });
111
- if (isMatch) {
112
- node.arguments[0] = t.stringLiteral(replaceValue);
113
- }
114
- }
115
- },
116
- },
117
- },
118
- };
119
- }
120
- exports.default = default_1;
@@ -1,18 +0,0 @@
1
- import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
2
- import type { IOpts } from './awaitImport';
3
- export declare function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, }: {
4
- value: string;
5
- path?: Babel.NodePath;
6
- opts?: IOpts;
7
- isExportAll?: boolean;
8
- depth?: number;
9
- cache?: Map<string, any>;
10
- filename?: string;
11
- }): {
12
- isMatch: boolean;
13
- replaceValue: string;
14
- };
15
- export declare function getPath({ value, opts }: {
16
- value: string;
17
- opts: IOpts;
18
- }): string;
@@ -1,127 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getPath = exports.checkMatch = void 0;
7
- const utils_1 = require("@umijs/utils");
8
- const assert_1 = __importDefault(require("assert"));
9
- const path_1 = require("path");
10
- const getAliasedPath_1 = require("./getAliasedPath");
11
- const isExternals_1 = require("./isExternals");
12
- // const UNMATCH_LIBS = ['umi', 'dumi', '@alipay/bigfish'];
13
- const RE_NODE_MODULES = /node_modules/;
14
- const RE_UMI_LOCAL_DEV = /umi(-next)?\/packages\//;
15
- function isUmiLocalDev(path) {
16
- return RE_UMI_LOCAL_DEV.test((0, utils_1.winPath)(path));
17
- }
18
- function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, }) {
19
- var _a, _b;
20
- let isMatch;
21
- let replaceValue = '';
22
- depth = depth || 1;
23
- (0, assert_1.default)(depth <= 10, `endless loop detected in checkMatch, please check your alias config.`);
24
- opts = opts || {};
25
- const remoteName = opts.remoteName || 'mf';
26
- // FIXME: hard code for vite mode
27
- value = value.replace(/^@fs\//, '/');
28
- if (
29
- // unMatch specified libs
30
- ((_a = opts.unMatchLibs) === null || _a === void 0 ? void 0 : _a.includes(value)) ||
31
- // do not match bundler-webpack/client/client/client.js
32
- value.includes('client/client/client.js') ||
33
- // already handled
34
- value.startsWith(`${remoteName}/`) ||
35
- // don't match dynamic path
36
- // e.g. @umijs/deps/compiled/babel/svgr-webpack.js?-svgo,+titleProp,+ref!./umi.svg
37
- (0, utils_1.winPath)(value).includes('babel/svgr-webpack') ||
38
- // don't match webpack loader
39
- // e.g. !!dumi-raw-code-loader!/path/to/VerticalProgress/index.module.less?dumi-raw-code
40
- value.startsWith('!!') ||
41
- // don't match externals
42
- (0, isExternals_1.isExternals)({ value, externals: opts.externals }) ||
43
- // relative import
44
- value.startsWith('.')) {
45
- isMatch = false;
46
- }
47
- else if ((0, path_1.isAbsolute)(value)) {
48
- isMatch = RE_NODE_MODULES.test(value) || isUmiLocalDev(value);
49
- }
50
- else {
51
- const aliasedPath = (0, getAliasedPath_1.getAliasedPath)({
52
- value,
53
- alias: opts.alias || {},
54
- });
55
- if (aliasedPath) {
56
- return checkMatch({
57
- value: aliasedPath,
58
- path,
59
- opts,
60
- isExportAll,
61
- depth: depth + 1,
62
- cache,
63
- filename,
64
- });
65
- }
66
- else {
67
- isMatch = true;
68
- }
69
- }
70
- if (isMatch && isExportAll) {
71
- isMatch = !!(opts.exportAllMembers && value in opts.exportAllMembers);
72
- }
73
- if (isMatch) {
74
- replaceValue = `${remoteName}/${(0, utils_1.winPath)(value)}`;
75
- }
76
- // @ts-ignore
77
- const file = (path === null || path === void 0 ? void 0 : path.hub.file.opts.filename) || filename;
78
- (_b = opts.onTransformDeps) === null || _b === void 0 ? void 0 : _b.call(opts, {
79
- sourceValue: value,
80
- replaceValue,
81
- isMatch,
82
- file,
83
- });
84
- if (cache) {
85
- let mod;
86
- if (cache.has(file)) {
87
- mod = cache.get(file);
88
- }
89
- else {
90
- mod = {
91
- matched: new Set(),
92
- unMatched: new Set(),
93
- };
94
- cache.set(file, mod);
95
- }
96
- mod[isMatch ? 'matched' : 'unMatched'].add({
97
- sourceValue: value,
98
- replaceValue,
99
- file,
100
- });
101
- }
102
- // console.log(
103
- // '> check',
104
- // // @ts-ignore
105
- // path.hub.file.opts.filename,
106
- // value,
107
- // cache,
108
- // 'isMatch',
109
- // isMatch,
110
- // );
111
- return {
112
- isMatch,
113
- replaceValue,
114
- };
115
- }
116
- exports.checkMatch = checkMatch;
117
- // TODO: REMOVE ME
118
- function getPath({ value, opts }) {
119
- const alias = opts.alias || {};
120
- for (const key of Object.keys(alias)) {
121
- if (value.startsWith(key)) {
122
- return value.replace(key, alias[key]);
123
- }
124
- }
125
- return value;
126
- }
127
- exports.getPath = getPath;
@@ -1,4 +0,0 @@
1
- export declare function getAliasedPath({ value, alias, }: {
2
- value: string;
3
- alias: Record<string, string>;
4
- }): string | undefined;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAliasedPath = void 0;
4
- function getAliasedPath({ value, alias, }) {
5
- const importValue = value;
6
- // equal alias
7
- if (alias[value]) {
8
- return alias[value];
9
- }
10
- for (const key of Object.keys(alias)) {
11
- const aliasValue = alias[key];
12
- // exact alias
13
- // ref: https://webpack.js.org/configuration/resolve/#resolvealias
14
- // e.g. foo$: path/to/foo
15
- if (key.endsWith('$')) {
16
- if (importValue === key.slice(0, -1))
17
- return aliasValue;
18
- else
19
- continue;
20
- }
21
- // e.g. foo: path/to/foo.js
22
- if (importValue.startsWith(addLastSlash(key))) {
23
- return importValue.replace(key, aliasValue);
24
- }
25
- }
26
- }
27
- exports.getAliasedPath = getAliasedPath;
28
- function addLastSlash(path) {
29
- return path.endsWith('/') ? path : `${path}/`;
30
- }
@@ -1,4 +0,0 @@
1
- export declare function getRealPath(opts: {
2
- file: string;
3
- dep: string;
4
- }): string | null;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRealPath = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const FILE_EXT_NAMES = ['.tsx', '.ts', '.jsx', '.mjs', '.js'];
7
- function getRealPath(opts) {
8
- const target = (0, path_1.isAbsolute)(opts.dep)
9
- ? opts.dep
10
- : (0, path_1.join)((0, path_1.dirname)(opts.file), opts.dep);
11
- if (FILE_EXT_NAMES.includes((0, path_1.extname)(target))) {
12
- return target;
13
- }
14
- else {
15
- for (const fileExtName of FILE_EXT_NAMES) {
16
- const targetWithExtName = `${target}${fileExtName}`;
17
- if ((0, fs_1.existsSync)(targetWithExtName)) {
18
- return targetWithExtName;
19
- }
20
- }
21
- return null;
22
- }
23
- }
24
- exports.getRealPath = getRealPath;
@@ -1,11 +0,0 @@
1
- declare type IExternal = Record<string, string> | Function;
2
- declare type IExternals = IExternal[] | IExternal;
3
- export declare function isExternals({ value, externals, }: {
4
- value: string;
5
- externals: IExternals;
6
- }): boolean;
7
- export declare function isExternal({ value, external, }: {
8
- value: string;
9
- external: IExternal;
10
- }): boolean;
11
- export {};
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isExternal = exports.isExternals = void 0;
4
- function isExternals({ value, externals, }) {
5
- const externalsArr = Array.isArray(externals) ? externals : [externals];
6
- for (const external of externalsArr) {
7
- if (isExternal({ value, external })) {
8
- return true;
9
- }
10
- }
11
- return false;
12
- }
13
- exports.isExternals = isExternals;
14
- function isExternal({ value, external, }) {
15
- if (typeof external === 'object') {
16
- return !!external[value];
17
- }
18
- else if (typeof external === 'function') {
19
- let ret = false;
20
- external({}, value, (_, b) => {
21
- ret = !!b;
22
- });
23
- return ret;
24
- }
25
- else {
26
- return false;
27
- }
28
- }
29
- exports.isExternal = isExternal;
@@ -1 +0,0 @@
1
- export declare function parseSpecifiers(specifiers: any[]): any;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = 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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.parseSpecifiers = void 0;
27
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
28
- const DEFAULT = 'default';
29
- function parseSpecifiers(specifiers) {
30
- return specifiers.reduce((memo, s) => {
31
- if (t.isImportDefaultSpecifier(s)) {
32
- memo.properties.push(t.objectProperty(t.identifier(DEFAULT), s.local));
33
- }
34
- else if (t.isExportDefaultSpecifier(s)) {
35
- memo.properties.push(t.objectProperty(t.identifier(DEFAULT), s.exported));
36
- }
37
- else if (t.isExportSpecifier(s)) {
38
- if (t.isIdentifier(s.exported, { name: DEFAULT })) {
39
- memo.defaultIdentifier = s.local.name;
40
- memo.properties.push(t.objectProperty(s.local, s.local));
41
- }
42
- else {
43
- memo.properties.push(t.objectProperty(s.local, s.exported));
44
- }
45
- }
46
- else if (t.isImportNamespaceSpecifier(s)) {
47
- memo.namespaceIdentifier = s.local;
48
- }
49
- else {
50
- memo.properties.push(t.objectProperty(s.imported, s.local));
51
- }
52
- return memo;
53
- }, { properties: [], namespaceIdentifier: null, defaultIdentifier: null });
54
- }
55
- exports.parseSpecifiers = parseSpecifiers;
@@ -1,7 +0,0 @@
1
- export declare const MF_VA_PREFIX = "mf-va_";
2
- export declare const MF_DEP_PREFIX = "mf-dep_";
3
- export declare const MF_STATIC_PREFIX = "mf-static/";
4
- export declare const DEFAULT_MF_NAME = "mf";
5
- export declare const DEFAULT_TMP_DIR_NAME = ".mfsu";
6
- export declare const REMOTE_FILE = "remoteEntry.js";
7
- export declare const REMOTE_FILE_FULL: string;
package/dist/constants.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REMOTE_FILE_FULL = exports.REMOTE_FILE = exports.DEFAULT_TMP_DIR_NAME = exports.DEFAULT_MF_NAME = exports.MF_STATIC_PREFIX = exports.MF_DEP_PREFIX = exports.MF_VA_PREFIX = void 0;
4
- exports.MF_VA_PREFIX = 'mf-va_';
5
- exports.MF_DEP_PREFIX = 'mf-dep_';
6
- exports.MF_STATIC_PREFIX = 'mf-static/';
7
- exports.DEFAULT_MF_NAME = 'mf';
8
- exports.DEFAULT_TMP_DIR_NAME = '.mfsu';
9
- exports.REMOTE_FILE = 'remoteEntry.js';
10
- exports.REMOTE_FILE_FULL = `${exports.MF_VA_PREFIX}${exports.REMOTE_FILE}`;
package/dist/dep/dep.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { MFSU } from '../mfsu';
2
- export declare class Dep {
3
- file: string;
4
- version: string;
5
- cwd: string;
6
- shortFile: string;
7
- normalizedFile: string;
8
- filePath: string;
9
- mfsu: MFSU;
10
- constructor(opts: {
11
- file: string;
12
- version: string;
13
- cwd: string;
14
- mfsu: MFSU;
15
- });
16
- buildExposeContent(): Promise<string>;
17
- getRealFile(): Promise<string | null>;
18
- static buildDeps(opts: {
19
- deps: Record<string, {
20
- file: string;
21
- version: string;
22
- }>;
23
- cwd: string;
24
- mfsu: MFSU;
25
- }): Dep[];
26
- static getDepVersion(opts: {
27
- dep: string;
28
- cwd: string;
29
- }): string;
30
- }
package/dist/dep/dep.js DELETED
@@ -1,107 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Dep = void 0;
16
- const utils_1 = require("@umijs/utils");
17
- const assert_1 = __importDefault(require("assert"));
18
- const enhanced_resolve_1 = __importDefault(require("enhanced-resolve"));
19
- const fs_1 = require("fs");
20
- const path_1 = require("path");
21
- const constants_1 = require("../constants");
22
- const trimFileContent_1 = require("../utils/trimFileContent");
23
- const getExposeFromContent_1 = require("./getExposeFromContent");
24
- const resolver = enhanced_resolve_1.default.create({
25
- mainFields: ['module', 'browser', 'main'],
26
- extensions: ['.js', '.json', '.mjs'],
27
- exportsFields: ['exports'],
28
- conditionNames: ['import', 'module', 'require', 'node'],
29
- });
30
- function resolve(context, path) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- return new Promise((resolve, reject) => {
33
- resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
34
- });
35
- });
36
- }
37
- class Dep {
38
- constructor(opts) {
39
- this.file = (0, utils_1.winPath)(opts.file);
40
- this.version = opts.version;
41
- this.cwd = opts.cwd;
42
- this.shortFile = this.file;
43
- this.normalizedFile = this.shortFile.replace(/\//g, '_').replace(/:/g, '_');
44
- this.filePath = `${constants_1.MF_VA_PREFIX}${this.normalizedFile}.js`;
45
- this.mfsu = opts.mfsu;
46
- }
47
- buildExposeContent() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- // node natives
50
- // @ts-ignore
51
- const isNodeNatives = !!process.binding('natives')[this.file];
52
- if (isNodeNatives) {
53
- return (0, trimFileContent_1.trimFileContent)(this.mfsu.opts.excludeNodeNatives
54
- ? `
55
- const _ = require('${this.file}');
56
- module.exports = _;
57
- `
58
- : `
59
- import _ from '${this.file}';
60
- export default _;
61
- export * from '${this.file}';
62
- `);
63
- }
64
- // none node natives
65
- const realFile = yield this.getRealFile();
66
- (0, assert_1.default)(realFile, `filePath not found of ${this.file}`);
67
- const content = (0, fs_1.readFileSync)(realFile, 'utf-8');
68
- return yield (0, getExposeFromContent_1.getExposeFromContent)({
69
- content,
70
- filePath: realFile,
71
- dep: this,
72
- });
73
- });
74
- }
75
- getRealFile() {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- try {
78
- // don't need to handle alias here
79
- // it's already handled by babel plugin
80
- return yield resolve(this.cwd, this.file);
81
- }
82
- catch (e) {
83
- return null;
84
- }
85
- });
86
- }
87
- static buildDeps(opts) {
88
- return Object.keys(opts.deps).map((file) => {
89
- return new Dep(Object.assign(Object.assign({}, opts.deps[file]), { cwd: opts.cwd, mfsu: opts.mfsu }));
90
- });
91
- }
92
- static getDepVersion(opts) {
93
- // @ts-ignore
94
- if (!!process.binding('natives')[opts.dep]) {
95
- return '*';
96
- }
97
- const dep = (0, path_1.isAbsolute)(opts.dep)
98
- ? opts.dep
99
- : (0, path_1.join)(opts.cwd, 'node_modules', opts.dep);
100
- const pkg = utils_1.pkgUp.pkgUpSync({
101
- cwd: dep,
102
- });
103
- (0, assert_1.default)(pkg, `package.json not found for ${opts.dep}`);
104
- return require(pkg).version;
105
- }
106
- }
107
- exports.Dep = Dep;
@@ -1,3 +0,0 @@
1
- export declare function getCJSExports({ content }: {
2
- content: string;
3
- }): string[];