@nocobase/build 0.7.0-alpha.56

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 (53) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +0 -0
  3. package/bin/nocobase-build.js +71 -0
  4. package/lib/babel.js +252 -0
  5. package/lib/build.js +351 -0
  6. package/lib/es5ImcompatibleVersions.js +51 -0
  7. package/lib/getBabelConfig.js +75 -0
  8. package/lib/getRollupConfig.js +320 -0
  9. package/lib/getUserConfig.js +99 -0
  10. package/lib/importLibToEs.js +38 -0
  11. package/lib/index.js +13 -0
  12. package/lib/normalizeBundleOpts.js +35 -0
  13. package/lib/randomColor.js +32 -0
  14. package/lib/registerBabel.js +38 -0
  15. package/lib/rollup.js +144 -0
  16. package/lib/schema.js +213 -0
  17. package/lib/types.d.js +1 -0
  18. package/lib/utils/getLernaPackages/index.js +63 -0
  19. package/lib/utils/index.js +48 -0
  20. package/package.json +78 -0
  21. package/src/babel.ts +257 -0
  22. package/src/build.ts +260 -0
  23. package/src/es5ImcompatibleVersions.ts +33 -0
  24. package/src/getBabelConfig.ts +95 -0
  25. package/src/getRollupConfig.ts +343 -0
  26. package/src/getUserConfig.ts +87 -0
  27. package/src/importLibToEs.js +26 -0
  28. package/src/index.ts +3 -0
  29. package/src/normalizeBundleOpts.ts +24 -0
  30. package/src/randomColor.ts +34 -0
  31. package/src/registerBabel.ts +23 -0
  32. package/src/rollup.ts +77 -0
  33. package/src/schema.ts +175 -0
  34. package/src/types.d.ts +118 -0
  35. package/src/utils/getLernaPackages/fixtures/customize/core/core1/package.json +7 -0
  36. package/src/utils/getLernaPackages/fixtures/customize/core/core1/src/index.js +2 -0
  37. package/src/utils/getLernaPackages/fixtures/customize/core/core2/package.json +5 -0
  38. package/src/utils/getLernaPackages/fixtures/customize/core/core2/src/index.js +2 -0
  39. package/src/utils/getLernaPackages/fixtures/customize/lerna.json +6 -0
  40. package/src/utils/getLernaPackages/fixtures/customize/package.json +4 -0
  41. package/src/utils/getLernaPackages/fixtures/customize/packages/bar/package.json +4 -0
  42. package/src/utils/getLernaPackages/fixtures/customize/packages/bar/src/index.js +2 -0
  43. package/src/utils/getLernaPackages/fixtures/customize/packages/foo/package.json +7 -0
  44. package/src/utils/getLernaPackages/fixtures/customize/packages/foo/src/index.js +2 -0
  45. package/src/utils/getLernaPackages/fixtures/default/lerna.json +1 -0
  46. package/src/utils/getLernaPackages/fixtures/default/package.json +4 -0
  47. package/src/utils/getLernaPackages/fixtures/default/packages/bar/package.json +4 -0
  48. package/src/utils/getLernaPackages/fixtures/default/packages/bar/src/index.js +2 -0
  49. package/src/utils/getLernaPackages/fixtures/default/packages/foo/package.json +7 -0
  50. package/src/utils/getLernaPackages/fixtures/default/packages/foo/src/index.js +2 -0
  51. package/src/utils/getLernaPackages/index.ts +57 -0
  52. package/src/utils/index.ts +13 -0
  53. package/template/tsconfig.json +23 -0
@@ -0,0 +1,320 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+
8
+ var _fs = require("fs");
9
+
10
+ var _path = require("path");
11
+
12
+ var _pluginUrl = _interopRequireDefault(require("@rollup/plugin-url"));
13
+
14
+ var _pluginJson = _interopRequireDefault(require("@rollup/plugin-json"));
15
+
16
+ var _pluginReplace = _interopRequireDefault(require("@rollup/plugin-replace"));
17
+
18
+ var _pluginCommonjs = _interopRequireDefault(require("@rollup/plugin-commonjs"));
19
+
20
+ var _pluginNodeResolve = _interopRequireDefault(require("@rollup/plugin-node-resolve"));
21
+
22
+ var _pluginInject = _interopRequireDefault(require("@rollup/plugin-inject"));
23
+
24
+ var _pluginBabel = _interopRequireDefault(require("@rollup/plugin-babel"));
25
+
26
+ var _pluginutils = require("@rollup/pluginutils");
27
+
28
+ var _rollupPluginPostcss = _interopRequireDefault(require("rollup-plugin-postcss"));
29
+
30
+ var _rollupPluginTerser = require("rollup-plugin-terser");
31
+
32
+ var _rollupPluginTypescript = _interopRequireDefault(require("rollup-plugin-typescript2"));
33
+
34
+ var _lodash = require("lodash");
35
+
36
+ var _tempDir = _interopRequireDefault(require("temp-dir"));
37
+
38
+ var _autoprefixer = _interopRequireDefault(require("autoprefixer"));
39
+
40
+ var _lessPluginNpmImport = _interopRequireDefault(require("less-plugin-npm-import"));
41
+
42
+ var _rollup = _interopRequireDefault(require("@svgr/rollup"));
43
+
44
+ var _getBabelConfig = _interopRequireDefault(require("./getBabelConfig"));
45
+
46
+ var _es5ImcompatibleVersions = require("./es5ImcompatibleVersions");
47
+
48
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
49
+
50
+ 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; }
51
+
52
+ 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; }
53
+
54
+ 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; }
55
+
56
+ function _default(opts) {
57
+ const type = opts.type,
58
+ entry = opts.entry,
59
+ cwd = opts.cwd,
60
+ rootPath = opts.rootPath,
61
+ importLibToEs = opts.importLibToEs,
62
+ bundleOpts = opts.bundleOpts;
63
+ const umd = bundleOpts.umd,
64
+ esm = bundleOpts.esm,
65
+ cjs = bundleOpts.cjs,
66
+ file = bundleOpts.file,
67
+ _bundleOpts$target = bundleOpts.target,
68
+ target = _bundleOpts$target === void 0 ? 'browser' : _bundleOpts$target,
69
+ _bundleOpts$extractCS = bundleOpts.extractCSS,
70
+ extractCSS = _bundleOpts$extractCS === void 0 ? false : _bundleOpts$extractCS,
71
+ _bundleOpts$injectCSS = bundleOpts.injectCSS,
72
+ injectCSS = _bundleOpts$injectCSS === void 0 ? true : _bundleOpts$injectCSS,
73
+ modules = bundleOpts.cssModules,
74
+ _bundleOpts$extraPost = bundleOpts.extraPostCSSPlugins,
75
+ extraPostCSSPlugins = _bundleOpts$extraPost === void 0 ? [] : _bundleOpts$extraPost,
76
+ _bundleOpts$extraBabe = bundleOpts.extraBabelPresets,
77
+ extraBabelPresets = _bundleOpts$extraBabe === void 0 ? [] : _bundleOpts$extraBabe,
78
+ _bundleOpts$extraBabe2 = bundleOpts.extraBabelPlugins,
79
+ extraBabelPlugins = _bundleOpts$extraBabe2 === void 0 ? [] : _bundleOpts$extraBabe2,
80
+ _bundleOpts$extraRoll = bundleOpts.extraRollupPlugins,
81
+ extraRollupPlugins = _bundleOpts$extraRoll === void 0 ? [] : _bundleOpts$extraRoll,
82
+ autoprefixerOpts = bundleOpts.autoprefixer,
83
+ _bundleOpts$include = bundleOpts.include,
84
+ include = _bundleOpts$include === void 0 ? /node_modules/ : _bundleOpts$include,
85
+ runtimeHelpersOpts = bundleOpts.runtimeHelpers,
86
+ replaceOpts = bundleOpts.replace,
87
+ injectOpts = bundleOpts.inject,
88
+ _bundleOpts$extraExte = bundleOpts.extraExternals,
89
+ extraExternals = _bundleOpts$extraExte === void 0 ? [] : _bundleOpts$extraExte,
90
+ _bundleOpts$externals = bundleOpts.externalsExclude,
91
+ externalsExclude = _bundleOpts$externals === void 0 ? [] : _bundleOpts$externals,
92
+ nodeVersion = bundleOpts.nodeVersion,
93
+ typescriptOpts = bundleOpts.typescriptOpts,
94
+ _bundleOpts$nodeResol = bundleOpts.nodeResolveOpts,
95
+ nodeResolveOpts = _bundleOpts$nodeResol === void 0 ? {} : _bundleOpts$nodeResol,
96
+ disableTypeCheck = bundleOpts.disableTypeCheck,
97
+ _bundleOpts$lessInRol = bundleOpts.lessInRollupMode,
98
+ lessInRollupMode = _bundleOpts$lessInRol === void 0 ? {} : _bundleOpts$lessInRol,
99
+ _bundleOpts$sassInRol = bundleOpts.sassInRollupMode,
100
+ sassInRollupMode = _bundleOpts$sassInRol === void 0 ? {} : _bundleOpts$sassInRol;
101
+ const entryExt = (0, _path.extname)(entry);
102
+ const name = file || (0, _path.basename)(entry, entryExt);
103
+ const isTypeScript = entryExt === '.ts' || entryExt === '.tsx';
104
+ const extensions = ['.js', '.jsx', '.ts', '.tsx', '.es6', '.es', '.mjs'];
105
+ let pkg = {};
106
+
107
+ try {
108
+ pkg = require((0, _path.join)(cwd, 'package.json')); // eslint-disable-line
109
+ } catch (e) {} // cjs 不给浏览器用,所以无需 runtimeHelpers
110
+
111
+
112
+ const runtimeHelpers = type === 'cjs' ? false : runtimeHelpersOpts;
113
+
114
+ const babelOpts = _objectSpread(_objectSpread({}, (0, _getBabelConfig.default)({
115
+ type,
116
+ target: type === 'esm' ? 'browser' : target,
117
+ // watch 模式下有几率走的 babel?原因未知。
118
+ // ref: https://github.com/umijs/father/issues/158
119
+ typescript: true,
120
+ runtimeHelpers,
121
+ nodeVersion
122
+ }).opts), {}, {
123
+ // ref: https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers
124
+ babelHelpers: runtimeHelpers ? 'runtime' : 'bundled',
125
+ // exclude: /\/node_modules\//,
126
+ filter: filePath => {
127
+ const rollupFilter = (0, _pluginutils.createFilter)(null, /\/node_modules\//); // 默认过滤 node_modules
128
+
129
+ if (!rollupFilter(filePath)) {
130
+ const pkgPath = (0, _es5ImcompatibleVersions.getPkgPath)(filePath);
131
+ return (0, _es5ImcompatibleVersions.shouldTransform)(pkgPath);
132
+ }
133
+
134
+ return true;
135
+ },
136
+ babelrc: false,
137
+ // ref: https://github.com/rollup/rollup-plugin-babel#usage
138
+ extensions
139
+ });
140
+
141
+ if (importLibToEs && type === 'esm') {
142
+ babelOpts.plugins.push(require.resolve('../lib/importLibToEs'));
143
+ }
144
+
145
+ babelOpts.presets.push(...extraBabelPresets);
146
+ babelOpts.plugins.push(...extraBabelPlugins); // rollup configs
147
+
148
+ const input = (0, _path.join)(cwd, entry);
149
+ const format = type; // ref: https://rollupjs.org/guide/en#external
150
+ // 潜在问题:引用包的子文件时会报 warning,比如 @babel/runtime/helpers/esm/createClass
151
+ // 解决方案:可以用 function 处理
152
+
153
+ const external = [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {}), ...extraExternals]; // umd 只要 external peerDependencies
154
+
155
+ const externalPeerDeps = [...Object.keys(pkg.peerDependencies || {}), ...extraExternals];
156
+
157
+ function getPkgNameByid(id) {
158
+ const splitted = id.split('/'); // @ 和 @tmp 是为了兼容 umi 的逻辑
159
+
160
+ if (id.charAt(0) === '@' && splitted[0] !== '@' && splitted[0] !== '@tmp') {
161
+ return splitted.slice(0, 2).join('/');
162
+ } else {
163
+ return id.split('/')[0];
164
+ }
165
+ }
166
+
167
+ function testExternal(pkgs, excludes, id) {
168
+ if (excludes.includes(id)) {
169
+ return false;
170
+ }
171
+
172
+ return pkgs.includes(getPkgNameByid(id));
173
+ }
174
+
175
+ const terserOpts = {
176
+ compress: {
177
+ pure_getters: true,
178
+ unsafe: true,
179
+ unsafe_comps: true,
180
+ warnings: false
181
+ }
182
+ }; // https://github.com/umijs/father/issues/164
183
+
184
+ function mergePlugins(defaultRollupPlugins = [], extraRollupPlugins = []) {
185
+ const pluginsMap = Object.assign(defaultRollupPlugins.reduce((r, plugin) => _objectSpread(_objectSpread({}, r), {}, {
186
+ [plugin.name]: plugin
187
+ }), {}), extraRollupPlugins.reduce((r, plugin) => _objectSpread(_objectSpread({}, r), {}, {
188
+ [plugin.name]: plugin
189
+ }), {}));
190
+ return Object.values(pluginsMap);
191
+ }
192
+
193
+ function getPlugins(opts = {}) {
194
+ const minCSS = opts.minCSS;
195
+ const defaultRollupPlugins = [(0, _pluginUrl.default)(), (0, _rollup.default)(), (0, _rollupPluginPostcss.default)(_objectSpread(_objectSpread({
196
+ extract: extractCSS,
197
+ inject: injectCSS,
198
+ modules
199
+ }, modules ? {
200
+ autoModules: false
201
+ } : {}), {}, {
202
+ minimize: !!minCSS,
203
+ use: {
204
+ less: _objectSpread({
205
+ plugins: [new _lessPluginNpmImport.default({
206
+ prefix: '~'
207
+ })],
208
+ javascriptEnabled: true
209
+ }, lessInRollupMode),
210
+ sass: _objectSpread({}, sassInRollupMode),
211
+ stylus: false
212
+ },
213
+ plugins: [(0, _autoprefixer.default)(_objectSpread({
214
+ // https://github.com/postcss/autoprefixer/issues/776
215
+ remove: false
216
+ }, autoprefixerOpts)), ...extraPostCSSPlugins]
217
+ })), ...(injectOpts ? [(0, _pluginInject.default)(injectOpts)] : []), ...(replaceOpts && Object.keys(replaceOpts || {}).length ? [(0, _pluginReplace.default)(replaceOpts)] : []), (0, _pluginNodeResolve.default)(_objectSpread({
218
+ mainFields: ['module', 'jsnext:main', 'main'],
219
+ extensions
220
+ }, nodeResolveOpts)), ...(isTypeScript ? [(0, _rollupPluginTypescript.default)(_objectSpread({
221
+ cwd,
222
+ // @see https://github.com/umijs/father/issues/61#issuecomment-544822774
223
+ clean: true,
224
+ cacheRoot: `${_tempDir.default}/.rollup_plugin_typescript2_cache`,
225
+ // 支持往上找 tsconfig.json
226
+ // 比如 lerna 的场景不需要每个 package 有个 tsconfig.json
227
+ tsconfig: [(0, _path.join)(cwd, 'tsconfig.json'), (0, _path.join)(rootPath, 'tsconfig.json')].find(_fs.existsSync),
228
+ tsconfigDefaults: {
229
+ compilerOptions: {
230
+ // Generate declaration files by default
231
+ declaration: true
232
+ }
233
+ },
234
+ tsconfigOverride: {
235
+ compilerOptions: {
236
+ // Support dynamic import
237
+ target: 'esnext'
238
+ }
239
+ },
240
+ check: !disableTypeCheck
241
+ }, typescriptOpts || {}))] : []), (0, _pluginBabel.default)(babelOpts), (0, _pluginJson.default)()];
242
+ return mergePlugins(defaultRollupPlugins, extraRollupPlugins || []);
243
+ }
244
+
245
+ switch (type) {
246
+ case 'esm':
247
+ const output = {
248
+ dir: (0, _path.join)(cwd, `${esm && esm.dir || 'dist'}`),
249
+ entryFileNames: `${esm && esm.file || `${name}.esm`}.js`
250
+ };
251
+ return [{
252
+ input,
253
+ output: _objectSpread({
254
+ format
255
+ }, output),
256
+ plugins: [...getPlugins(), ...(esm && esm.minify ? [(0, _rollupPluginTerser.terser)(terserOpts)] : [])],
257
+ external: testExternal.bind(null, external, externalsExclude)
258
+ }, ...(esm && esm.mjs ? [{
259
+ input,
260
+ output: {
261
+ format,
262
+ file: (0, _path.join)(cwd, `dist/${esm && esm.file || `${name}`}.mjs`)
263
+ },
264
+ plugins: [...getPlugins(), (0, _pluginReplace.default)({
265
+ 'process.env.NODE_ENV': JSON.stringify('production')
266
+ }), (0, _rollupPluginTerser.terser)(terserOpts)],
267
+ external: testExternal.bind(null, externalPeerDeps, externalsExclude)
268
+ }] : [])];
269
+
270
+ case 'cjs':
271
+ return [{
272
+ input,
273
+ output: {
274
+ format,
275
+ file: (0, _path.join)(cwd, `dist/${cjs && cjs.file || name}.js`)
276
+ },
277
+ plugins: [...getPlugins(), ...(cjs && cjs.minify ? [(0, _rollupPluginTerser.terser)(terserOpts)] : [])],
278
+ external: testExternal.bind(null, external, externalsExclude)
279
+ }];
280
+
281
+ case 'umd':
282
+ // Add umd related plugins
283
+ const extraUmdPlugins = [(0, _pluginCommonjs.default)({
284
+ include // namedExports options has been remove from https://github.com/rollup/plugins/pull/149
285
+
286
+ })];
287
+ return [{
288
+ input,
289
+ output: {
290
+ format,
291
+ sourcemap: umd && umd.sourcemap,
292
+ file: (0, _path.join)(cwd, `dist/${umd && umd.file || `${name}.umd`}.js`),
293
+ globals: umd && umd.globals,
294
+ name: umd && umd.name || pkg.name && (0, _lodash.camelCase)((0, _path.basename)(pkg.name))
295
+ },
296
+ plugins: [...extraUmdPlugins, ...getPlugins(), (0, _pluginReplace.default)({
297
+ 'process.env.NODE_ENV': JSON.stringify('development')
298
+ })],
299
+ external: testExternal.bind(null, externalPeerDeps, externalsExclude)
300
+ }, ...(umd && umd.minFile === false ? [] : [{
301
+ input,
302
+ output: {
303
+ format,
304
+ sourcemap: umd && umd.sourcemap,
305
+ file: (0, _path.join)(cwd, `dist/${umd && umd.file || `${name}.umd`}.min.js`),
306
+ globals: umd && umd.globals,
307
+ name: umd && umd.name || pkg.name && (0, _lodash.camelCase)((0, _path.basename)(pkg.name))
308
+ },
309
+ plugins: [...extraUmdPlugins, ...getPlugins({
310
+ minCSS: true
311
+ }), (0, _pluginReplace.default)({
312
+ 'process.env.NODE_ENV': JSON.stringify('production')
313
+ }), (0, _rollupPluginTerser.terser)(terserOpts)],
314
+ external: testExternal.bind(null, externalPeerDeps, externalsExclude)
315
+ }])];
316
+
317
+ default:
318
+ throw new Error(`Unsupported type ${type}`);
319
+ }
320
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CONFIG_FILES = void 0;
7
+ exports.default = _default;
8
+
9
+ var _ajv = _interopRequireDefault(require("ajv"));
10
+
11
+ var _fs = require("fs");
12
+
13
+ var _path = require("path");
14
+
15
+ var _signale = _interopRequireDefault(require("signale"));
16
+
17
+ var _slash = _interopRequireDefault(require("slash2"));
18
+
19
+ var _schema = _interopRequireDefault(require("./schema"));
20
+
21
+ var _utils = require("./utils");
22
+
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
+
25
+ function testDefault(obj) {
26
+ return obj.default || obj;
27
+ }
28
+
29
+ const CONFIG_FILES = ['.buildrc.js', '.buildrc.jsx', '.buildrc.ts', '.buildrc.tsx', '.fatherrc.js', '.fatherrc.jsx', '.fatherrc.ts', '.fatherrc.tsx', '.umirc.library.js', '.umirc.library.jsx', '.umirc.library.ts', '.umirc.library.tsx'];
30
+ exports.CONFIG_FILES = CONFIG_FILES;
31
+ const CLASSES = {
32
+ Function: Function
33
+ };
34
+
35
+ const extendAjv = ajv => {
36
+ ajv.addKeyword('instanceof', {
37
+ compile: function compile(schema) {
38
+ var Class = CLASSES[schema];
39
+ return function (data) {
40
+ return data instanceof Class;
41
+ };
42
+ }
43
+ });
44
+ return ajv;
45
+ };
46
+
47
+ function _default({
48
+ cwd,
49
+ customPath
50
+ }) {
51
+ let finalPath = '';
52
+
53
+ if (customPath) {
54
+ finalPath = (0, _path.isAbsolute)(customPath) ? customPath : (0, _path.resolve)(process.cwd(), customPath);
55
+
56
+ if (!(0, _fs.existsSync)(finalPath)) {
57
+ throw new Error(`can\'t found config file: ${customPath}`);
58
+ }
59
+ }
60
+
61
+ const configFile = finalPath || (0, _utils.getExistFile)({
62
+ cwd,
63
+ files: CONFIG_FILES,
64
+ returnRelative: false
65
+ });
66
+
67
+ if (configFile) {
68
+ if (configFile.includes('.umirc.library.')) {
69
+ _signale.default.warn(`.umirc.library.js is deprecated, please use .fatherrc.js instead.`);
70
+ }
71
+
72
+ const userConfig = testDefault(require(configFile)); // eslint-disable-line
73
+
74
+ const userConfigs = Array.isArray(userConfig) ? userConfig : [userConfig];
75
+ userConfigs.forEach(userConfig => {
76
+ const ajv = extendAjv(new _ajv.default({
77
+ allErrors: true
78
+ }));
79
+ const isValid = ajv.validate(_schema.default, userConfig);
80
+
81
+ if (!isValid) {
82
+ const errors = ajv.errors.map(({
83
+ dataPath,
84
+ message
85
+ }, index) => {
86
+ return `${index + 1}. ${dataPath}${dataPath ? ' ' : ''}${message}`;
87
+ });
88
+ throw new Error(`
89
+ Invalid options in ${(0, _slash.default)((0, _path.relative)(cwd, configFile))}
90
+
91
+ ${errors.join('\n')}
92
+ `.trim());
93
+ }
94
+ });
95
+ return userConfig;
96
+ } else {
97
+ return {};
98
+ }
99
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _path = require("path");
9
+
10
+ var _fs = _interopRequireDefault(require("fs"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const cwd = process.cwd();
15
+
16
+ function replacePath(path) {
17
+ if (path.node.source && /\/lib\//.test(path.node.source.value)) {
18
+ const esModule = path.node.source.value.replace('/lib/', '/es/');
19
+ const esPath = (0, _path.dirname)((0, _path.join)(cwd, `node_modules/${esModule}`));
20
+
21
+ if (_fs.default.existsSync(esPath)) {
22
+ console.log(`[es build] replace ${path.node.source.value} with ${esModule}`);
23
+ path.node.source.value = esModule;
24
+ }
25
+ }
26
+ }
27
+
28
+ function replaceLib() {
29
+ return {
30
+ visitor: {
31
+ ImportDeclaration: replacePath,
32
+ ExportNamedDeclaration: replacePath
33
+ }
34
+ };
35
+ }
36
+
37
+ var _default = replaceLib;
38
+ exports.default = _default;
package/lib/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _build = _interopRequireDefault(require("./build"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ var _default = _build.default;
13
+ exports.default = _default;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+
8
+ var _lodash = require("lodash");
9
+
10
+ function stripDotSlashPrefix(path) {
11
+ return path.replace(/^\.\//, '');
12
+ }
13
+
14
+ function _default(entry, opts) {
15
+ let clone = (0, _lodash.cloneDeep)(opts);
16
+ const stripedEntry = stripDotSlashPrefix(entry);
17
+
18
+ if (clone.overridesByEntry) {
19
+ Object.keys(clone.overridesByEntry).forEach(key => {
20
+ const stripedKey = stripDotSlashPrefix(key);
21
+
22
+ if (stripedKey !== key) {
23
+ clone.overridesByEntry[stripedKey] = clone.overridesByEntry[key];
24
+ }
25
+ });
26
+
27
+ if (clone.overridesByEntry[stripedEntry]) {
28
+ clone = (0, _lodash.merge)(clone, clone.overridesByEntry[stripedEntry]);
29
+ }
30
+
31
+ delete clone.overridesByEntry;
32
+ }
33
+
34
+ return clone;
35
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const colors = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'gray', 'redBright', 'greenBright', 'yellowBright', 'blueBright', 'magentaBright', 'cyanBright'];
13
+ let index = 0;
14
+ const cache = {};
15
+
16
+ function _default(pkg) {
17
+ if (!cache[pkg]) {
18
+ const color = colors[index];
19
+
20
+ let str = _chalk.default[color].bold(pkg);
21
+
22
+ cache[pkg] = str;
23
+
24
+ if (index === colors.length - 1) {
25
+ index = 0;
26
+ } else {
27
+ index += 1;
28
+ }
29
+ }
30
+
31
+ return cache[pkg];
32
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+
8
+ var _path = require("path");
9
+
10
+ var _slash = _interopRequireDefault(require("slash2"));
11
+
12
+ var _getBabelConfig2 = _interopRequireDefault(require("./getBabelConfig"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
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; }
17
+
18
+ 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; }
19
+
20
+ 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; }
21
+
22
+ function _default(opts) {
23
+ const cwd = opts.cwd,
24
+ only = opts.only;
25
+
26
+ const _getBabelConfig = (0, _getBabelConfig2.default)({
27
+ target: 'node',
28
+ typescript: true
29
+ }),
30
+ babelConfig = _getBabelConfig.opts;
31
+
32
+ require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
33
+ extensions: ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx'],
34
+ only: only.map(file => (0, _slash.default)((0, _path.isAbsolute)(file) ? file : (0, _path.join)(cwd, file))),
35
+ babelrc: false,
36
+ cache: false
37
+ }));
38
+ }