ko 5.3.9 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
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
+ const commander_1 = __importDefault(require("./commander"));
7
+ const hooks_1 = __importDefault(require("./hooks"));
8
+ const config_1 = __importDefault(require("./config"));
9
+ class Service extends hooks_1.default {
10
+ constructor() {
11
+ super();
12
+ this.commander = new commander_1.default();
13
+ this.config = new config_1.default().generate();
14
+ this.config.plugins && this.config.plugins.forEach(p => this.register(p));
15
+ }
16
+ freezeCliOptsWith(cliOpts) {
17
+ this.cliOpts = Object.freeze(cliOpts);
18
+ }
19
+ run() {
20
+ this.commander.parse();
21
+ }
22
+ }
23
+ exports.default = Service;
package/lib/types.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ACTION = void 0;
4
+ var ACTION;
5
+ (function (ACTION) {
6
+ ACTION["ADD"] = "add";
7
+ ACTION["UPDATE"] = "update";
8
+ })(ACTION = exports.ACTION || (exports.ACTION = {}));
@@ -0,0 +1,22 @@
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.assert = exports.getResolvePath = exports.getCacheIdentifier = void 0;
7
+ function getCacheIdentifier(env, pkgs) {
8
+ let cacheIdentifier = env || '';
9
+ Object.values(pkgs).forEach(pkgName => {
10
+ cacheIdentifier += `:${pkgName}@`;
11
+ cacheIdentifier += require(`${pkgName}/package.json`).version || '';
12
+ });
13
+ return cacheIdentifier;
14
+ }
15
+ exports.getCacheIdentifier = getCacheIdentifier;
16
+ function getResolvePath(name) {
17
+ const resolvePath = require.resolve(name);
18
+ return resolvePath;
19
+ }
20
+ exports.getResolvePath = getResolvePath;
21
+ var assert_1 = require("assert");
22
+ Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return __importDefault(assert_1).default; } });
@@ -3,67 +3,105 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const tsconfig_paths_webpack_plugin_1 = __importDefault(require("tsconfig-paths-webpack-plugin"));
7
- const config_1 = __importDefault(require("../utils/config"));
6
+ const path_1 = require("path");
7
+ const fs_1 = require("fs");
8
+ const lodash_1 = require("lodash");
8
9
  const loaders_1 = __importDefault(require("./loaders"));
9
10
  const plugins_1 = __importDefault(require("./plugins"));
10
- const extensions = [
11
- '.js',
12
- '.jsx',
13
- '.ts',
14
- '.tsx',
15
- '.css',
16
- '.scss',
17
- '.sass',
18
- '.less',
19
- '.json',
20
- '.html',
21
- ];
22
- function getWebpackBaseConf(opts) {
23
- const { ts = true, hash } = opts;
24
- const webpackBaseConf = {
25
- mode: config_1.default.isProductionEnv ? 'production' : 'development',
26
- target: 'web',
27
- context: config_1.default.cwd,
28
- entry: `src/index.${ts ? 'tsx' : 'js'}`,
29
- output: {
30
- path: config_1.default.defaultPaths.dist,
31
- filename: hash ? '[name].[contenthash].js' : '[name].js',
32
- publicPath: '/',
33
- },
34
- module: {
35
- rules: loaders_1.default,
36
- },
37
- plugins: (0, plugins_1.default)(),
38
- resolve: {
39
- extensions,
40
- plugins: [
41
- ts &&
42
- new tsconfig_paths_webpack_plugin_1.default({
43
- configFile: config_1.default.defaultPaths.tsconfig,
44
- }),
45
- ].filter(Boolean),
46
- fallback: {
47
- fs: false,
48
- path: false,
49
- events: false,
50
- os: require.resolve('os-browserify/browser'),
51
- crypto: require.resolve('crypto-browserify'),
52
- stream: require.resolve('stream-browserify'),
53
- buffer: require.resolve('buffer/'),
54
- string_decoder: require.resolve('string_decoder/'),
11
+ const utils_1 = require("../utils");
12
+ class WebpackConfig {
13
+ constructor(service) {
14
+ this.extensions = [
15
+ '.ts',
16
+ '.tsx',
17
+ '.js',
18
+ '.jsx',
19
+ '.css',
20
+ '.scss',
21
+ '.sass',
22
+ '.less',
23
+ '.json',
24
+ '.html',
25
+ ];
26
+ this.opts = { ...service.config, ...service.cliOpts };
27
+ this.env =
28
+ process.env.NODE_ENV === 'production' ? 'production' : 'development';
29
+ }
30
+ merge(...opts) {
31
+ return (0, lodash_1.merge)(this.base, ...opts);
32
+ }
33
+ get cache() {
34
+ const { experiment } = this.opts;
35
+ const type = experiment?.speedUp
36
+ ? 'filesystem'
37
+ : this.isProd
38
+ ? 'filesystem'
39
+ : 'memory';
40
+ const cache = {
41
+ type,
42
+ };
43
+ if (type === 'filesystem') {
44
+ cache.version = this.projectVersion;
45
+ }
46
+ else {
47
+ cache.maxGenerations = 1;
48
+ }
49
+ return cache;
50
+ }
51
+ get projectVersion() {
52
+ const pkgPath = (0, path_1.join)(this.opts.cwd, 'package.json');
53
+ (0, utils_1.assert)((0, fs_1.existsSync)(pkgPath), 'project package.json file not found');
54
+ return require(pkgPath).version;
55
+ }
56
+ get base() {
57
+ const { cwd, publicPath, entry, outputPath, alias, hash, analyzer } = this.opts;
58
+ const webpackBaseConf = {
59
+ mode: this.env,
60
+ target: 'web',
61
+ context: cwd,
62
+ entry,
63
+ output: {
64
+ path: outputPath,
65
+ filename: `js/[name].${hash ? '[contenthash].' : ''}js`,
66
+ publicPath,
55
67
  },
56
- },
57
- performance: {
58
- hints: false,
59
- },
60
- cache: {
61
- type: config_1.default.isProductionEnv ? 'filesystem' : 'memory',
62
- },
63
- stats: {
64
- cachedModules: false,
65
- },
66
- };
67
- return webpackBaseConf;
68
+ module: {
69
+ rules: (0, loaders_1.default)({
70
+ isProd: this.isProd,
71
+ ...this.opts,
72
+ }),
73
+ },
74
+ plugins: (0, plugins_1.default)({
75
+ isProd: this.isProd,
76
+ analyzer,
77
+ ...this.opts,
78
+ }),
79
+ resolve: {
80
+ extensions: this.extensions,
81
+ alias,
82
+ fallback: {
83
+ fs: false,
84
+ path: false,
85
+ events: false,
86
+ os: require.resolve('os-browserify/browser'),
87
+ crypto: require.resolve('crypto-browserify'),
88
+ stream: require.resolve('stream-browserify'),
89
+ buffer: require.resolve('buffer/'),
90
+ string_decoder: require.resolve('string_decoder/'),
91
+ },
92
+ },
93
+ performance: {
94
+ hints: false,
95
+ },
96
+ cache: this.cache,
97
+ stats: {
98
+ cachedModules: false,
99
+ },
100
+ };
101
+ return webpackBaseConf;
102
+ }
103
+ get isProd() {
104
+ return this.env === 'production';
105
+ }
68
106
  }
69
- exports.default = getWebpackBaseConf;
107
+ exports.default = WebpackConfig;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../../../utils");
4
+ class BabelLoader {
5
+ constructor(opts) {
6
+ this.BABEL_LOADER = (0, utils_1.getResolvePath)('babel-loader');
7
+ this.opts = opts;
8
+ }
9
+ get config() {
10
+ return {
11
+ loader: this.BABEL_LOADER,
12
+ options: {
13
+ presets: [
14
+ [
15
+ (0, utils_1.getResolvePath)('babel-preset-ko-app'),
16
+ {
17
+ useAbsoluteRuntime: true,
18
+ },
19
+ ],
20
+ ],
21
+ plugins: this.plugins,
22
+ babelrc: false,
23
+ configFile: false,
24
+ cacheIdentifier: this.cacheIdentifier,
25
+ cacheDirectory: !this.speedUp,
26
+ cacheCompression: false,
27
+ compact: this.opts.isProd,
28
+ },
29
+ };
30
+ }
31
+ get treasurePluginConfig() {
32
+ const babelPluginTreasurePath = (0, utils_1.getResolvePath)('babel-plugin-treasure');
33
+ return [
34
+ [
35
+ babelPluginTreasurePath,
36
+ {
37
+ libraryName: 'antd',
38
+ libraryDirectory: 'lib',
39
+ style: 'css',
40
+ },
41
+ 'antd',
42
+ ],
43
+ [
44
+ babelPluginTreasurePath,
45
+ {
46
+ libraryName: 'dt-react-component',
47
+ libraryDirectory: '/src/components/',
48
+ camel2DashComponentName: 'lower',
49
+ },
50
+ 'drc',
51
+ ],
52
+ //TODO: check lodash tree shaking in webpack 5
53
+ // [
54
+ // babelPluginTreasurePath,
55
+ // {
56
+ // libraryName: 'lodash',
57
+ // libraryDirectory: '/',
58
+ // camel2DashComponentName: false,
59
+ // },
60
+ // 'lodash',
61
+ // ],
62
+ ];
63
+ }
64
+ get plugins() {
65
+ return [...this.treasurePluginConfig].filter(Boolean);
66
+ }
67
+ get cacheIdentifier() {
68
+ return (0, utils_1.getCacheIdentifier)(this.opts.isProd ? 'production' : '', [
69
+ 'ko',
70
+ 'babel-preset-ko-app',
71
+ 'babel-plugin-treasure',
72
+ ]);
73
+ }
74
+ }
75
+ exports.default = BabelLoader;
@@ -6,5 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const style_1 = __importDefault(require("./style"));
7
7
  const asset_1 = __importDefault(require("./asset"));
8
8
  const script_1 = __importDefault(require("./script"));
9
- const loaders = [...style_1.default, ...asset_1.default, ...script_1.default];
9
+ const loaders = (opts) => {
10
+ const scripts = new script_1.default(opts);
11
+ const style = new style_1.default(opts);
12
+ return [...asset_1.default, ...style.config, ...scripts.config];
13
+ };
10
14
  exports.default = loaders;
@@ -3,64 +3,58 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const getCacheIdentifier_1 = __importDefault(require("react-dev-utils/getCacheIdentifier"));
7
- const config_1 = __importDefault(require("../../utils/config"));
8
- const THREAD_LOADER = require.resolve('thread-loader');
9
- const BABEL_LOADER = require.resolve('babel-loader');
10
- const WORKER_LOADER = require.resolve('worker-loader');
11
- const scriptLoader = [
12
- {
13
- test: /\.worker.[jt]s$/,
14
- loader: WORKER_LOADER,
15
- options: {
16
- inline: 'fallback',
17
- },
18
- },
19
- {
20
- test: /\.(t|j)sx?$/,
21
- include: (input) => {
22
- // internal modules dt-common compatible
23
- if (input.includes('node_modules/dt-common/src/')) {
24
- return true;
25
- }
26
- else if (input.includes('node_modules')) {
27
- return false;
28
- }
29
- else {
30
- return true;
31
- }
32
- },
33
- use: [
6
+ const babel_1 = __importDefault(require("./babel"));
7
+ class Script {
8
+ constructor(opts) {
9
+ this.THREAD_LOADER = require.resolve('thread-loader');
10
+ this.WORKER_LOADER = require.resolve('worker-loader');
11
+ this.ESBUILD_LOADER = require.resolve('esbuild-loader');
12
+ this.opts = opts;
13
+ this.BABEL_LOADER = new babel_1.default(opts);
14
+ }
15
+ get config() {
16
+ const scriptLoader = [
34
17
  {
35
- loader: THREAD_LOADER,
18
+ test: /\.worker.[jt]s$/,
19
+ loader: this.WORKER_LOADER,
36
20
  options: {
37
- workerNodeArgs: ['--max-old-space-size=4096'],
38
- name: 'ko-js-pool',
21
+ inline: 'fallback',
39
22
  },
40
23
  },
41
24
  {
42
- loader: BABEL_LOADER,
43
- options: {
44
- presets: [
45
- [
46
- require.resolve('babel-preset-ko-app'),
47
- {
48
- useAbsoluteRuntime: true,
49
- },
50
- ],
51
- ],
52
- plugins: config_1.default.isProductionEnv
53
- ? [require.resolve('react-refresh/babel')]
54
- : [],
55
- babelrc: false,
56
- configFile: false,
57
- cacheIdentifier: (0, getCacheIdentifier_1.default)(config_1.default.isProductionEnv ? 'production' : '', ['babel-preset-ko-app', 'react-dev-utils', 'ko']),
58
- cacheDirectory: true,
59
- cacheCompression: false,
60
- compact: config_1.default.isProductionEnv,
25
+ test: /\.(t|j)sx?$/,
26
+ include: (input) => {
27
+ // internal modules dt-common compatible
28
+ if (input.includes('node_modules/dt-common/src/')) {
29
+ return true;
30
+ }
31
+ else if (input.includes('node_modules')) {
32
+ return false;
33
+ }
34
+ else {
35
+ return true;
36
+ }
61
37
  },
38
+ use: [
39
+ {
40
+ loader: this.THREAD_LOADER,
41
+ options: {
42
+ name: 'ko-js-pool',
43
+ },
44
+ },
45
+ this.opts.experiment?.speedUp
46
+ ? {
47
+ loader: this.ESBUILD_LOADER,
48
+ options: {
49
+ loader: 'tsx',
50
+ target: 'es2020',
51
+ },
52
+ }
53
+ : this.BABEL_LOADER.config,
54
+ ].filter(Boolean),
62
55
  },
63
- ],
64
- },
65
- ];
66
- exports.default = scriptLoader;
56
+ ];
57
+ return scriptLoader;
58
+ }
59
+ }
60
+ exports.default = Script;