@modern-js/module-tools 2.0.0-beta.0 → 2.0.0-beta.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.
- package/CHANGELOG.md +102 -0
- package/dist/js/modern/cli/build.js +2 -1
- package/dist/js/modern/cli/dev.js +2 -2
- package/dist/js/modern/cli/new.js +0 -3
- package/dist/js/modern/commands/build.js +2 -6
- package/dist/js/modern/commands/dev.js +2 -5
- package/dist/js/modern/features/build/build-platform.js +11 -14
- package/dist/js/modern/features/build/bundle/runRollup.js +5 -18
- package/dist/js/modern/features/build/bundle/runSpeedy.js +6 -18
- package/dist/js/modern/features/build/bundleless/copy-assets.js +0 -8
- package/dist/js/modern/features/build/bundleless/generator-dts/index.js +7 -17
- package/dist/js/modern/features/build/bundleless/generator-dts/utils.js +6 -16
- package/dist/js/modern/features/build/bundleless/index.js +0 -2
- package/dist/js/modern/features/build/bundleless/runBabel.js +7 -34
- package/dist/js/modern/features/build/bundleless/style.js +1 -30
- package/dist/js/modern/features/build/constants.js +0 -3
- package/dist/js/modern/features/build/error.js +4 -27
- package/dist/js/modern/features/build/index.js +6 -15
- package/dist/js/modern/features/build/legacy-constants.js +8 -4
- package/dist/js/modern/features/build/logger/logText.js +0 -12
- package/dist/js/modern/features/build/logger/loggerManager.js +6 -19
- package/dist/js/modern/features/build/normalize.js +18 -43
- package/dist/js/modern/features/build/utils.js +5 -14
- package/dist/js/modern/features/dev/index.js +4 -9
- package/dist/js/modern/hooks/index.js +0 -3
- package/dist/js/modern/index.js +11 -11
- package/dist/js/modern/schema/build-config.js +2 -1
- package/dist/js/modern/schema/output.js +16 -10
- package/dist/js/modern/utils/babel.js +17 -15
- package/dist/js/modern/utils/copy.js +6 -15
- package/dist/js/modern/utils/init-env.js +0 -1
- package/dist/js/modern/utils/logger.js +1 -16
- package/dist/js/modern/utils/readline.js +2 -4
- package/dist/js/modern/utils/tsconfig.js +0 -1
- package/dist/js/modern/utils/tspaths-transform/constants.js +4 -2
- package/dist/js/modern/utils/tspaths-transform/index.js +2 -19
- package/dist/js/modern/utils/tspaths-transform/utils.js +0 -3
- package/dist/js/modern/utils/valide.js +10 -12
- package/dist/js/node/cli/build.js +2 -6
- package/dist/js/node/cli/dev.js +2 -7
- package/dist/js/node/cli/index.js +0 -6
- package/dist/js/node/cli/new.js +0 -8
- package/dist/js/node/commands/build.js +2 -21
- package/dist/js/node/commands/dev.js +2 -15
- package/dist/js/node/commands/index.js +0 -2
- package/dist/js/node/features/build/build-platform.js +11 -20
- package/dist/js/node/features/build/bundle/index.js +0 -6
- package/dist/js/node/features/build/bundle/runRollup.js +3 -32
- package/dist/js/node/features/build/bundle/runSpeedy.js +6 -32
- package/dist/js/node/features/build/bundleless/copy-assets.js +0 -20
- package/dist/js/node/features/build/bundleless/generator-dts/index.js +7 -27
- package/dist/js/node/features/build/bundleless/generator-dts/utils.js +6 -32
- package/dist/js/node/features/build/bundleless/index.js +0 -11
- package/dist/js/node/features/build/bundleless/runBabel.js +6 -60
- package/dist/js/node/features/build/bundleless/style.js +1 -50
- package/dist/js/node/features/build/constants.js +0 -11
- package/dist/js/node/features/build/error.js +4 -40
- package/dist/js/node/features/build/index.js +6 -38
- package/dist/js/node/features/build/legacy-constants.js +8 -4
- package/dist/js/node/features/build/logger/index.js +0 -4
- package/dist/js/node/features/build/logger/logText.js +0 -18
- package/dist/js/node/features/build/logger/loggerManager.js +5 -26
- package/dist/js/node/features/build/normalize.js +18 -61
- package/dist/js/node/features/build/utils.js +5 -30
- package/dist/js/node/features/dev/index.js +4 -17
- package/dist/js/node/hooks/build.js +0 -5
- package/dist/js/node/hooks/dev.js +0 -5
- package/dist/js/node/hooks/index.js +0 -10
- package/dist/js/node/index.js +12 -36
- package/dist/js/node/locale/index.js +0 -5
- package/dist/js/node/schema/build-config.js +2 -1
- package/dist/js/node/schema/index.js +0 -5
- package/dist/js/node/schema/output.js +16 -12
- package/dist/js/node/utils/babel.js +17 -23
- package/dist/js/node/utils/color.js +0 -3
- package/dist/js/node/utils/copy.js +6 -23
- package/dist/js/node/utils/init-env.js +0 -3
- package/dist/js/node/utils/json.js +0 -2
- package/dist/js/node/utils/language.js +0 -3
- package/dist/js/node/utils/logger.js +1 -26
- package/dist/js/node/utils/readline.js +0 -8
- package/dist/js/node/utils/tsconfig.js +0 -7
- package/dist/js/node/utils/tspaths-transform/constants.js +4 -2
- package/dist/js/node/utils/tspaths-transform/index.js +2 -34
- package/dist/js/node/utils/tspaths-transform/utils.js +0 -7
- package/dist/js/node/utils/valide.js +10 -17
- package/dist/types/commands/build.d.ts +0 -1
- package/dist/types/features/build/logger/loggerManager.d.ts +0 -1
- package/dist/types/features/build/normalize.d.ts +1 -1
- package/dist/types/features/build/utils.d.ts +0 -1
- package/dist/types/hooks/build.d.ts +6 -6
- package/dist/types/hooks/index.d.ts +3 -3
- package/dist/types/index.d.ts +0 -3
- package/dist/types/schema/types.d.ts +1 -3
- package/dist/types/types.d.ts +0 -1
- package/dist/types/utils/babel.d.ts +2 -2
- package/dist/types/utils/valide.d.ts +2 -2
- package/package.json +22 -22
|
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.dev = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
-
|
|
14
10
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
-
|
|
16
11
|
const devFeature = _utils.Import.lazy('../features/dev', require);
|
|
17
|
-
|
|
18
12
|
const tsConfigutils = _utils.Import.lazy('../utils/tsconfig', require);
|
|
19
|
-
|
|
20
13
|
const valid = _utils.Import.lazy('../utils/valide', require);
|
|
21
|
-
|
|
22
14
|
const existSubCmd = subCmd => subCmd.length > 0;
|
|
23
|
-
|
|
24
15
|
const dev = async (api, option, subCmd = '') => {
|
|
25
16
|
const {
|
|
26
17
|
tsconfig: tsconfigName
|
|
@@ -31,24 +22,21 @@ const dev = async (api, option, subCmd = '') => {
|
|
|
31
22
|
appDirectory
|
|
32
23
|
} = appContext;
|
|
33
24
|
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
34
|
-
|
|
35
25
|
_utils.dotenv.config();
|
|
36
|
-
|
|
37
26
|
valid.valideBeforeTask({
|
|
38
27
|
modernConfig,
|
|
39
28
|
tsconfigPath
|
|
40
29
|
});
|
|
41
30
|
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
|
|
42
|
-
|
|
43
31
|
if (existSubCmd(subCmd)) {
|
|
44
32
|
await devFeature.runSubCmd(api, subCmd, {
|
|
45
33
|
isTsProject,
|
|
46
34
|
appDirectory
|
|
47
35
|
});
|
|
48
36
|
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
37
|
+
}
|
|
51
38
|
|
|
39
|
+
// Compatible with the use of jupiter, RUN_PLATFORM is used in jupiter
|
|
52
40
|
if (process.env.RUN_PLATFORM) {
|
|
53
41
|
await devFeature.showMenu(api, {
|
|
54
42
|
isTsProject,
|
|
@@ -61,5 +49,4 @@ const dev = async (api, option, subCmd = '') => {
|
|
|
61
49
|
});
|
|
62
50
|
}
|
|
63
51
|
};
|
|
64
|
-
|
|
65
52
|
exports.dev = dev;
|
|
@@ -4,36 +4,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.buildPlatform = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
-
|
|
12
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
-
|
|
14
10
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
-
|
|
16
11
|
const lg = _utils.Import.lazy('./logger', require);
|
|
17
|
-
|
|
18
12
|
const pMap = _utils.Import.lazy('p-map', require);
|
|
19
|
-
|
|
20
13
|
const buildPlatform = async (api, option) => {
|
|
21
14
|
const {
|
|
22
15
|
isTsProject = false,
|
|
23
16
|
platform
|
|
24
17
|
} = option;
|
|
25
|
-
const lm = new lg.LoggerManager();
|
|
26
|
-
|
|
18
|
+
const lm = new lg.LoggerManager();
|
|
19
|
+
// 获取platforms的参数
|
|
27
20
|
const runners = api.useHookRunners();
|
|
28
21
|
const buildTasks = await runners.platformBuild({
|
|
29
22
|
isTsProject
|
|
30
23
|
});
|
|
31
|
-
|
|
32
24
|
if (buildTasks.length <= 0) {
|
|
33
25
|
console.info(_utils.chalk.yellow('No build tasks detected.\nYou can use the `new` command to enable the more features'));
|
|
34
26
|
return;
|
|
35
27
|
}
|
|
36
|
-
|
|
37
28
|
const loggerMap = {};
|
|
38
29
|
const taskMapper = buildTasks.filter(task => platform === 'all' || task.name === platform).map(params => {
|
|
39
30
|
const logger = lm.createLoggerText({
|
|
@@ -44,12 +35,10 @@ const buildPlatform = async (api, option) => {
|
|
|
44
35
|
logger
|
|
45
36
|
}, params);
|
|
46
37
|
});
|
|
47
|
-
|
|
48
38
|
if (taskMapper.length <= 0) {
|
|
49
39
|
console.info(_utils.chalk.yellow(`'${platform}' is undefined task`));
|
|
50
40
|
return;
|
|
51
41
|
}
|
|
52
|
-
|
|
53
42
|
lm.showCompiling();
|
|
54
43
|
await pMap(taskMapper, async ({
|
|
55
44
|
taskPath,
|
|
@@ -59,27 +48,29 @@ const buildPlatform = async (api, option) => {
|
|
|
59
48
|
const childProcess = _utils.execa.node(taskPath, params, {
|
|
60
49
|
stdio: 'inherit',
|
|
61
50
|
all: true
|
|
62
|
-
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// lm.addStdout(logger, childProcess.stdout, {
|
|
63
54
|
// event: { data: true, error: true },
|
|
64
55
|
// });
|
|
65
|
-
// lm.addStderr(logger, childProcess.stderr);
|
|
66
|
-
|
|
67
56
|
|
|
57
|
+
// lm.addStderr(logger, childProcess.stderr);
|
|
68
58
|
try {
|
|
69
59
|
await childProcess;
|
|
70
60
|
} catch (_unused) {
|
|
71
61
|
// eslint-disable-next-line no-process-exit
|
|
72
62
|
process.exit(1);
|
|
73
|
-
}
|
|
63
|
+
}
|
|
64
|
+
// lm.disappearCompiling();
|
|
74
65
|
// console.info(lg.colors.title(title));
|
|
75
66
|
// console.info(a.all);
|
|
76
|
-
|
|
77
67
|
}, {
|
|
78
68
|
concurrency: 1
|
|
79
|
-
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// lm.disappearCompiling();
|
|
80
72
|
// for (const key of Object.keys(loggerMap)) {
|
|
81
73
|
// console.info(loggerMap[key].value);
|
|
82
74
|
// }
|
|
83
75
|
};
|
|
84
|
-
|
|
85
76
|
exports.buildPlatform = buildPlatform;
|
|
@@ -4,20 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.build = void 0;
|
|
7
|
-
|
|
8
7
|
var _pMap = _interopRequireDefault(require("p-map"));
|
|
9
|
-
|
|
10
8
|
var _runSpeedy = require("./runSpeedy");
|
|
11
|
-
|
|
12
9
|
var _runRollup = require("./runRollup");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
const build = async (api, config) => {
|
|
17
12
|
const tasks = config.dtsOnly ? [_runRollup.startRollup] : [_runSpeedy.runSpeedy, _runRollup.startRollup];
|
|
18
13
|
await (0, _pMap.default)(tasks, async task => {
|
|
19
14
|
await task(api, config);
|
|
20
15
|
});
|
|
21
16
|
};
|
|
22
|
-
|
|
23
17
|
exports.build = build;
|
|
@@ -4,48 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.startRollup = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _typescript = _interopRequireDefault(require("typescript"));
|
|
11
|
-
|
|
12
9
|
var _rollupPluginHashbang = _interopRequireDefault(require("rollup-plugin-hashbang"));
|
|
13
|
-
|
|
14
10
|
var _pluginJson = _interopRequireDefault(require("@rollup/plugin-json"));
|
|
15
|
-
|
|
16
11
|
var _error = require("../error");
|
|
17
|
-
|
|
18
12
|
var _utils = require("../utils");
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
-
|
|
24
15
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
-
|
|
26
16
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
-
|
|
28
17
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
|
-
|
|
30
18
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
31
|
-
|
|
32
19
|
// Copied from https://github.com/egoist/tsup/blob/dev/src/rollup.ts
|
|
20
|
+
|
|
33
21
|
const loadCompilerOptions = tsconfig => {
|
|
34
22
|
if (!tsconfig) {
|
|
35
23
|
return {};
|
|
36
24
|
}
|
|
37
|
-
|
|
38
25
|
const configFile = _typescript.default.readConfigFile(tsconfig, _typescript.default.sys.readFile);
|
|
39
|
-
|
|
40
26
|
const {
|
|
41
27
|
options
|
|
42
28
|
} = _typescript.default.parseJsonConfigFileContent(configFile.config, _typescript.default.sys, './');
|
|
43
|
-
|
|
44
29
|
return options;
|
|
45
30
|
};
|
|
46
|
-
|
|
47
31
|
const dtsPlugin = require('rollup-plugin-dts');
|
|
48
|
-
|
|
49
32
|
const getRollupConfig = async (api, options) => {
|
|
50
33
|
const {
|
|
51
34
|
appDirectory
|
|
@@ -60,38 +43,30 @@ const getRollupConfig = async (api, options) => {
|
|
|
60
43
|
bundleOptions,
|
|
61
44
|
tsconfig
|
|
62
45
|
} = options;
|
|
63
|
-
|
|
64
46
|
const distDir = _path.default.join(appDirectory, distPath, outputPath);
|
|
65
|
-
|
|
66
47
|
const compilerOptions = loadCompilerOptions(tsconfig);
|
|
67
48
|
const dtsOptions = {
|
|
68
49
|
entry: bundleOptions.entry
|
|
69
50
|
};
|
|
70
51
|
const ignoreFiles = {
|
|
71
52
|
name: 'ignore-files',
|
|
72
|
-
|
|
73
53
|
load(id) {
|
|
74
54
|
if (!/\.(js|jsx|ts|tsx|json)$/.test(id)) {
|
|
75
55
|
return '';
|
|
76
56
|
}
|
|
77
|
-
|
|
78
57
|
return null;
|
|
79
58
|
}
|
|
80
|
-
|
|
81
59
|
};
|
|
82
60
|
return {
|
|
83
61
|
inputConfig: {
|
|
84
62
|
input: dtsOptions.entry,
|
|
85
63
|
external: bundleOptions.externals,
|
|
86
|
-
|
|
87
64
|
onwarn(warning, handler) {
|
|
88
65
|
if (warning.code === 'UNRESOLVED_IMPORT' || warning.code === 'CIRCULAR_DEPENDENCY' || warning.code === 'EMPTY_BUNDLE') {
|
|
89
66
|
return;
|
|
90
67
|
}
|
|
91
|
-
|
|
92
68
|
handler(warning);
|
|
93
69
|
},
|
|
94
|
-
|
|
95
70
|
plugins: [(0, _rollupPluginHashbang.default)(), (0, _pluginJson.default)(), ignoreFiles, dtsPlugin.default({
|
|
96
71
|
// use external to prevent them which come from node_modules from be bundled.
|
|
97
72
|
respectExternal: true,
|
|
@@ -121,7 +96,6 @@ const getRollupConfig = async (api, options) => {
|
|
|
121
96
|
}
|
|
122
97
|
};
|
|
123
98
|
};
|
|
124
|
-
|
|
125
99
|
async function runRollup(options, context) {
|
|
126
100
|
try {
|
|
127
101
|
const {
|
|
@@ -137,7 +111,6 @@ async function runRollup(options, context) {
|
|
|
137
111
|
}
|
|
138
112
|
}
|
|
139
113
|
}
|
|
140
|
-
|
|
141
114
|
async function watchRollup(options) {
|
|
142
115
|
const {
|
|
143
116
|
watch
|
|
@@ -151,15 +124,14 @@ async function watchRollup(options) {
|
|
|
151
124
|
console.info((0, _utils.watchSectionTitle)(titleText, _utils.SectionTitleStatus.Log));
|
|
152
125
|
} else if (event.code === 'BUNDLE_END') {
|
|
153
126
|
console.info((0, _utils.watchSectionTitle)(titleText, _utils.SectionTitleStatus.Success));
|
|
154
|
-
} else if (event.code === 'ERROR') {
|
|
127
|
+
} else if (event.code === 'ERROR') {
|
|
128
|
+
// this is dts rollup plugin bug, error not complete message
|
|
155
129
|
}
|
|
156
130
|
});
|
|
157
131
|
}
|
|
158
|
-
|
|
159
132
|
const startRollup = async (api, options) => {
|
|
160
133
|
if (options.enableDts) {
|
|
161
134
|
const config = await getRollupConfig(api, options);
|
|
162
|
-
|
|
163
135
|
if (options.watch) {
|
|
164
136
|
watchRollup(config);
|
|
165
137
|
} else {
|
|
@@ -170,5 +142,4 @@ const startRollup = async (api, options) => {
|
|
|
170
142
|
}
|
|
171
143
|
}
|
|
172
144
|
};
|
|
173
|
-
|
|
174
145
|
exports.startRollup = startRollup;
|
|
@@ -4,27 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.runSpeedy = exports.getDefine = exports.getAlias = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _speedyCore = require("@speedy-js/speedy-core");
|
|
11
|
-
|
|
12
9
|
var _speedyPluginEs = require("@speedy-js/speedy-plugin-es5");
|
|
13
|
-
|
|
14
10
|
var _utils = require("@modern-js/utils");
|
|
15
|
-
|
|
16
11
|
var _error = require("../error");
|
|
17
|
-
|
|
18
12
|
var _utils2 = require("../utils");
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
-
|
|
24
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
|
-
|
|
26
16
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
-
|
|
28
17
|
const getAlias = api => {
|
|
29
18
|
const {
|
|
30
19
|
appDirectory,
|
|
@@ -32,8 +21,8 @@ const getAlias = api => {
|
|
|
32
21
|
} = api.useAppContext();
|
|
33
22
|
const {
|
|
34
23
|
source
|
|
35
|
-
} = api.useResolvedConfigContext();
|
|
36
|
-
|
|
24
|
+
} = api.useResolvedConfigContext();
|
|
25
|
+
// TODO: maybe check tsconfig `paths`
|
|
37
26
|
const defaultAlias = {
|
|
38
27
|
'@': srcDirectory
|
|
39
28
|
};
|
|
@@ -44,9 +33,7 @@ const getAlias = api => {
|
|
|
44
33
|
});
|
|
45
34
|
}, {});
|
|
46
35
|
};
|
|
47
|
-
|
|
48
36
|
exports.getAlias = getAlias;
|
|
49
|
-
|
|
50
37
|
const getDefine = api => {
|
|
51
38
|
const {
|
|
52
39
|
source: {
|
|
@@ -64,9 +51,7 @@ const getDefine = api => {
|
|
|
64
51
|
}, {});
|
|
65
52
|
return _objectSpread(_objectSpread({}, envVarsDefine), globalVarsDefine);
|
|
66
53
|
};
|
|
67
|
-
|
|
68
54
|
exports.getDefine = getDefine;
|
|
69
|
-
|
|
70
55
|
const getStyleOptionFromModern = async api => {
|
|
71
56
|
const runner = api.useHookRunners();
|
|
72
57
|
const {
|
|
@@ -89,13 +74,10 @@ const getStyleOptionFromModern = async api => {
|
|
|
89
74
|
onLast: async _ => undefined
|
|
90
75
|
});
|
|
91
76
|
const postcssOption = (0, _utils2.getPostcssOption)(appDirectory, modernConfig);
|
|
92
|
-
|
|
93
77
|
if (tailwindPlugin) {
|
|
94
78
|
var _postcssOption$plugin;
|
|
95
|
-
|
|
96
79
|
(_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
|
|
97
80
|
}
|
|
98
|
-
|
|
99
81
|
return {
|
|
100
82
|
less: lessOption === null || lessOption === void 0 ? void 0 : lessOption.lessOption,
|
|
101
83
|
sass: sassOption,
|
|
@@ -104,7 +86,6 @@ const getStyleOptionFromModern = async api => {
|
|
|
104
86
|
})
|
|
105
87
|
};
|
|
106
88
|
};
|
|
107
|
-
|
|
108
89
|
const runSpeedy = async (api, config) => {
|
|
109
90
|
const {
|
|
110
91
|
appDirectory
|
|
@@ -115,6 +96,8 @@ const runSpeedy = async (api, config) => {
|
|
|
115
96
|
},
|
|
116
97
|
tools: {
|
|
117
98
|
speedy: userSpeedyConfig
|
|
99
|
+
} = {
|
|
100
|
+
speedy: undefined
|
|
118
101
|
}
|
|
119
102
|
} = api.useResolvedConfigContext();
|
|
120
103
|
const {
|
|
@@ -133,30 +116,24 @@ const runSpeedy = async (api, config) => {
|
|
|
133
116
|
externals,
|
|
134
117
|
getModuleId
|
|
135
118
|
} = bundleOptions;
|
|
136
|
-
|
|
137
119
|
const distDir = _path.default.join(appDirectory, distPath, outputPath);
|
|
138
|
-
|
|
139
120
|
const titleText = `[Bundle:Speedy:${format}_${target}]`;
|
|
140
121
|
const style = await getStyleOptionFromModern(api);
|
|
141
122
|
const alias = getAlias(api);
|
|
142
123
|
const define = getDefine(api);
|
|
143
|
-
|
|
144
124
|
const watchPlugin = () => {
|
|
145
125
|
return {
|
|
146
126
|
name: 'watch-plugin',
|
|
147
|
-
|
|
148
127
|
apply(compiler) {
|
|
149
128
|
compiler.hooks.watchChange.tap('watch-plugin', async () => {
|
|
150
129
|
console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Log));
|
|
151
130
|
});
|
|
152
131
|
}
|
|
153
|
-
|
|
154
132
|
};
|
|
155
133
|
};
|
|
156
|
-
|
|
157
134
|
const plugins = target === 'es5' ? [(0, _speedyPluginEs.es5InputPlugin)()] : [];
|
|
158
|
-
plugins.push(watchPlugin());
|
|
159
|
-
|
|
135
|
+
plugins.push(watchPlugin());
|
|
136
|
+
// TODO: add speedy plugin about react
|
|
160
137
|
const internalSpeedyConfig = {
|
|
161
138
|
command: 'build',
|
|
162
139
|
mode: 'production',
|
|
@@ -187,12 +164,10 @@ const runSpeedy = async (api, config) => {
|
|
|
187
164
|
};
|
|
188
165
|
const speedyConfig = (0, _utils.applyOptionsChain)(internalSpeedyConfig, userSpeedyConfig);
|
|
189
166
|
const compiler = await _speedyCore.SpeedyBundler.create(speedyConfig);
|
|
190
|
-
|
|
191
167
|
try {
|
|
192
168
|
if (watch) {
|
|
193
169
|
console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Log));
|
|
194
170
|
}
|
|
195
|
-
|
|
196
171
|
await compiler.build();
|
|
197
172
|
} catch (e) {
|
|
198
173
|
/**
|
|
@@ -208,5 +183,4 @@ const runSpeedy = async (api, config) => {
|
|
|
208
183
|
}
|
|
209
184
|
}
|
|
210
185
|
};
|
|
211
|
-
|
|
212
186
|
exports.runSpeedy = runSpeedy;
|
|
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.copyStaticAssets = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
-
|
|
14
10
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
-
|
|
16
11
|
const copyUtils = _utils.Import.lazy('../../../utils/copy', require);
|
|
17
|
-
|
|
18
12
|
const SRC_DIRS = 'src';
|
|
19
|
-
|
|
20
13
|
const copyAssets = ({
|
|
21
14
|
targetDir,
|
|
22
15
|
outputDir
|
|
@@ -24,20 +17,15 @@ const copyAssets = ({
|
|
|
24
17
|
const assetsFiles = _utils.glob.sync(`${targetDir}/**/*.*`, {
|
|
25
18
|
ignore: ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']
|
|
26
19
|
});
|
|
27
|
-
|
|
28
20
|
if (assetsFiles.length > 0) {
|
|
29
21
|
_utils.fs.ensureDirSync(outputDir);
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
for (const resource of assetsFiles) {
|
|
33
24
|
const file = path.relative(targetDir, resource);
|
|
34
|
-
|
|
35
25
|
_utils.fs.ensureDirSync(path.dirname(path.resolve(outputDir, file)));
|
|
36
|
-
|
|
37
26
|
_utils.fs.copyFileSync(resource, path.resolve(outputDir, file));
|
|
38
27
|
}
|
|
39
28
|
};
|
|
40
|
-
|
|
41
29
|
const watchAssets = (api, {
|
|
42
30
|
targetDir,
|
|
43
31
|
outputDir
|
|
@@ -48,21 +36,15 @@ const watchAssets = (api, {
|
|
|
48
36
|
}) => {
|
|
49
37
|
if (changeType === _utils.WatchChangeType.UNLINK) {
|
|
50
38
|
const removeFile = path.normalize(`${outputDir}/${path.relative(targetDir, changedFilePath)}`);
|
|
51
|
-
|
|
52
39
|
_utils.fs.removeSync(removeFile);
|
|
53
|
-
|
|
54
40
|
return;
|
|
55
41
|
}
|
|
56
|
-
|
|
57
42
|
const file = path.relative(targetDir, changedFilePath);
|
|
58
|
-
|
|
59
43
|
_utils.fs.copyFileSync(changedFilePath, path.resolve(outputDir, file));
|
|
60
44
|
}, ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']);
|
|
61
45
|
};
|
|
62
|
-
|
|
63
46
|
const copyStaticAssets = async (api, config) => {
|
|
64
47
|
var _bundlelessOptions$so;
|
|
65
|
-
|
|
66
48
|
const appContext = api.useAppContext();
|
|
67
49
|
const modernConfig = api.useResolvedConfigContext();
|
|
68
50
|
const {
|
|
@@ -92,7 +74,6 @@ const copyStaticAssets = async (api, config) => {
|
|
|
92
74
|
modernConfig,
|
|
93
75
|
appContext
|
|
94
76
|
});
|
|
95
|
-
|
|
96
77
|
if (config.watch) {
|
|
97
78
|
watchAssets(api, {
|
|
98
79
|
targetDir: srcDir,
|
|
@@ -100,5 +81,4 @@ const copyStaticAssets = async (api, config) => {
|
|
|
100
81
|
});
|
|
101
82
|
}
|
|
102
83
|
};
|
|
103
|
-
|
|
104
84
|
exports.copyStaticAssets = copyStaticAssets;
|
|
@@ -4,34 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.genDts = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _error = require("../../error");
|
|
13
|
-
|
|
14
10
|
var _utils2 = require("../../utils");
|
|
15
|
-
|
|
16
11
|
var _utils3 = require("./utils");
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
const utils = _utils.Import.lazy('./utils', require);
|
|
21
|
-
|
|
22
14
|
const getProjectTsconfig = tsconfigPath => {
|
|
23
15
|
if (!tsconfigPath || !_utils.fs.existsSync(tsconfigPath)) {
|
|
24
16
|
return {};
|
|
25
17
|
}
|
|
26
|
-
|
|
27
18
|
return _utils.json5.parse(_utils.fs.readFileSync(tsconfigPath, 'utf-8'));
|
|
28
19
|
};
|
|
29
|
-
|
|
30
20
|
const resolveLog = (childProgress, {
|
|
31
21
|
watch: _watch = false
|
|
32
22
|
} = {}) => {
|
|
33
23
|
var _childProgress$stdout, _childProgress$stdout2, _childProgress$stderr;
|
|
34
|
-
|
|
35
24
|
/**
|
|
36
25
|
* tsc 所有的log信息都是从stdout data 事件中获取
|
|
37
26
|
* 正常模式下,如果有报错信息,交给 resolveLog 后面的逻辑来处理
|
|
@@ -42,8 +31,8 @@ const resolveLog = (childProgress, {
|
|
|
42
31
|
console.info((0, _utils2.watchSectionTitle)('[Bundleless:DTS]', _utils2.SectionTitleStatus.Log));
|
|
43
32
|
console.info(data.toString());
|
|
44
33
|
}
|
|
45
|
-
});
|
|
46
|
-
|
|
34
|
+
});
|
|
35
|
+
// 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况
|
|
47
36
|
(_childProgress$stdout2 = childProgress.stdout) === null || _childProgress$stdout2 === void 0 ? void 0 : _childProgress$stdout2.on('error', error => {
|
|
48
37
|
console.error(error.message);
|
|
49
38
|
});
|
|
@@ -51,7 +40,6 @@ const resolveLog = (childProgress, {
|
|
|
51
40
|
console.error(chunk.toString());
|
|
52
41
|
});
|
|
53
42
|
};
|
|
54
|
-
|
|
55
43
|
const generatorDts = async (_, config) => {
|
|
56
44
|
const {
|
|
57
45
|
tsconfigPath,
|
|
@@ -68,9 +56,9 @@ const generatorDts = async (_, config) => {
|
|
|
68
56
|
});
|
|
69
57
|
const tscBinFile = (0, _utils3.getTscBinPath)(appDirectory);
|
|
70
58
|
const watchParams = watch ? ['-w'] : [];
|
|
71
|
-
const childProgress = (0, _utils.execa)(tscBinFile, ['-p', willDeleteTsconfigPath,
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
const childProgress = (0, _utils.execa)(tscBinFile, ['-p', willDeleteTsconfigPath, /* Required parameter, use it stdout have color */
|
|
60
|
+
'--pretty',
|
|
61
|
+
// https://github.com/microsoft/TypeScript/issues/21824
|
|
74
62
|
'--preserveWatchOutput', ...watchParams], {
|
|
75
63
|
stdio: 'pipe',
|
|
76
64
|
cwd: appDirectory
|
|
@@ -78,7 +66,6 @@ const generatorDts = async (_, config) => {
|
|
|
78
66
|
resolveLog(childProgress, {
|
|
79
67
|
watch
|
|
80
68
|
});
|
|
81
|
-
|
|
82
69
|
try {
|
|
83
70
|
await childProgress;
|
|
84
71
|
} catch (e) {
|
|
@@ -88,10 +75,8 @@ const generatorDts = async (_, config) => {
|
|
|
88
75
|
});
|
|
89
76
|
}
|
|
90
77
|
}
|
|
91
|
-
|
|
92
78
|
_utils.fs.removeSync(willDeleteTsconfigPath);
|
|
93
79
|
};
|
|
94
|
-
|
|
95
80
|
const genDts = async (api, config) => {
|
|
96
81
|
const {
|
|
97
82
|
outputPath,
|
|
@@ -102,11 +87,9 @@ const genDts = async (api, config) => {
|
|
|
102
87
|
},
|
|
103
88
|
enableDts
|
|
104
89
|
} = config;
|
|
105
|
-
|
|
106
90
|
if (!enableDts) {
|
|
107
91
|
return;
|
|
108
92
|
}
|
|
109
|
-
|
|
110
93
|
const {
|
|
111
94
|
appDirectory
|
|
112
95
|
} = api.useAppContext();
|
|
@@ -116,9 +99,7 @@ const genDts = async (api, config) => {
|
|
|
116
99
|
path: distPath = 'dist'
|
|
117
100
|
}
|
|
118
101
|
} = modernConfig;
|
|
119
|
-
|
|
120
102
|
const distDir = _path.default.join(appDirectory, distPath, outputPath);
|
|
121
|
-
|
|
122
103
|
const option = {
|
|
123
104
|
appDirectory,
|
|
124
105
|
distDir,
|
|
@@ -126,9 +107,8 @@ const genDts = async (api, config) => {
|
|
|
126
107
|
watch,
|
|
127
108
|
sourceDir
|
|
128
109
|
};
|
|
129
|
-
await generatorDts(modernConfig, option);
|
|
130
|
-
|
|
110
|
+
await generatorDts(modernConfig, option);
|
|
111
|
+
// TODO: watch 模式下无法转换
|
|
131
112
|
utils.resolveAlias(modernConfig, option);
|
|
132
113
|
};
|
|
133
|
-
|
|
134
114
|
exports.genDts = genDts;
|