ko 5.2.2 → 5.3.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.
@@ -17,11 +17,12 @@ class Build extends creator_1.WebpackCreator {
17
17
  optimization: {
18
18
  minimizer: [
19
19
  !esbuild && new CssMinimizerPlugin(),
20
- esbuild && new esbuild_loader_1.ESBuildMinifyPlugin({
21
- target: 'es2015',
22
- css: true
23
- })
24
- ].filter(Boolean)
20
+ esbuild &&
21
+ new esbuild_loader_1.ESBuildMinifyPlugin({
22
+ target: 'es2015',
23
+ css: true,
24
+ }),
25
+ ].filter(Boolean),
25
26
  },
26
27
  plugins: [
27
28
  new webpack_1.default.optimize.SplitChunksPlugin({
@@ -50,8 +51,8 @@ class Build extends creator_1.WebpackCreator {
50
51
  reuseExistingChunk: true,
51
52
  },
52
53
  },
53
- })
54
- ]
54
+ }),
55
+ ],
55
56
  };
56
57
  return this.mergeConfig([this.baseConfig, conf]);
57
58
  }
@@ -61,7 +62,7 @@ class Build extends creator_1.WebpackCreator {
61
62
  if (stats && stats.hasErrors()) {
62
63
  throw stats.toString({
63
64
  logging: 'warn',
64
- colors: true
65
+ colors: true,
65
66
  });
66
67
  }
67
68
  if (error) {
@@ -20,29 +20,25 @@ class Dev extends creator_1.WebpackCreator {
20
20
  const defaultDevServerConfig = {
21
21
  port,
22
22
  host,
23
- contentBase: config_1.default.defaultPaths.dist,
24
23
  historyApiFallback: true,
25
- disableHostCheck: true,
26
- compress: true,
27
- clientLogLevel: 'none',
24
+ allowedHosts: 'all',
28
25
  hot: true,
29
- inline: true,
30
- publicPath: '/',
31
- watchOptions: {
32
- ignored: /node_modules/,
33
- aggregateTimeout: 600,
26
+ static: {
27
+ directory: config_1.default.defaultPaths.dist,
28
+ publicPath: '/',
29
+ watch: true,
34
30
  },
35
- open: true
31
+ client: {
32
+ overlay: false,
33
+ },
34
+ setupExitSignals: true,
36
35
  };
37
36
  return { ...defaultDevServerConfig, ...userDefinedDevServerConfig };
38
37
  }
39
38
  config() {
40
39
  const conf = {
41
40
  devtool: 'cheap-module-source-map',
42
- plugins: [
43
- new webpack_1.default.HotModuleReplacementPlugin(),
44
- this.opts.analyzer && new BundleAnalyzerPlugin()
45
- ].filter(Boolean),
41
+ plugins: [this.opts.analyzer && new BundleAnalyzerPlugin()].filter(Boolean),
46
42
  };
47
43
  return this.mergeConfig([this.baseConfig, conf]);
48
44
  }
@@ -71,39 +67,20 @@ class Dev extends creator_1.WebpackCreator {
71
67
  return this.changePort(newPort, port);
72
68
  }
73
69
  }
74
- getUrlHost(host) {
75
- const regex = /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*$/i;
76
- return regex.test(host) ? host : `http://${host}`;
77
- }
78
70
  async action() {
79
- const { port, host } = this.devSerConf();
71
+ const devSerConf = this.devSerConf();
72
+ const { port } = devSerConf;
80
73
  const newPort = await this.checkPort(parseInt(port));
81
- if (!newPort)
82
- return;
83
- webpack_dev_server_1.default.addDevServerEntrypoints(this.config(), this.devSerConf());
74
+ if (!newPort) {
75
+ process.exit(0);
76
+ }
77
+ devSerConf.port = newPort;
84
78
  const compiler = (0, webpack_1.default)(this.config());
85
- const devServer = new webpack_dev_server_1.default(compiler, this.devSerConf());
86
- let isFirstCompile = true;
87
- compiler.hooks.done.tap('done', (stats) => {
88
- if (isFirstCompile) {
89
- isFirstCompile = false;
90
- this.successStdout('development server has been started');
91
- console.log(`server starts at: ${this.linkStdout(this.getUrlHost(host) + ':' + port)}`);
92
- }
93
- if (stats.hasErrors()) {
94
- console.log(stats.toString({
95
- colors: true
96
- }));
97
- }
98
- });
99
- compiler.hooks.invalid.tap('invalid', () => {
100
- console.log('Compiling...');
101
- });
102
- devServer.listen(port, host, (err) => {
103
- if (err) {
104
- console.error(err);
105
- process.exit(500);
106
- }
79
+ const devServer = new webpack_dev_server_1.default(devSerConf, compiler);
80
+ await devServer.start();
81
+ process.stdin.on('end', () => {
82
+ devServer.stop();
83
+ process.exit(0);
107
84
  });
108
85
  }
109
86
  }
package/lib/cli.js CHANGED
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const commander_1 = require("commander");
8
- const ko_lints_1 = __importDefault(require("ko-lints"));
9
8
  const build_1 = __importDefault(require("./actions/build"));
10
9
  const dev_1 = __importDefault(require("./actions/dev"));
11
10
  const program = new commander_1.Command();
@@ -21,6 +20,7 @@ program
21
20
  .option('-t,--ts,--typescript', 'support typescript')
22
21
  .option('-e,--esbuild', 'enable esbuild')
23
22
  .action((opts) => {
23
+ process.env.NODE_ENV = 'production';
24
24
  const buildInstance = new build_1.default(opts);
25
25
  buildInstance.action();
26
26
  });
@@ -36,6 +36,4 @@ program
36
36
  const devInstance = new dev_1.default(opts);
37
37
  devInstance.action();
38
38
  });
39
- //attach lint features to program
40
- (0, ko_lints_1.default)(program);
41
39
  program.parse();
@@ -4,22 +4,23 @@ const path_1 = require("path");
4
4
  const fs_1 = require("fs");
5
5
  class Config {
6
6
  constructor() {
7
+ this.babelPlugins = [];
7
8
  this.cwd = process.cwd();
8
9
  }
9
10
  static getInstance() {
10
11
  if (!Config.instance) {
11
- Config.instance = new Config();
12
+ Config.instance = Object.freeze(new Config());
12
13
  }
13
14
  return Config.instance;
14
15
  }
15
16
  getFileRealPath(path) {
16
17
  return (0, path_1.isAbsolute)(path) ? path : (0, path_1.resolve)(this.cwd, path);
17
18
  }
18
- //TODO: define userConf
19
19
  get userConf() {
20
20
  const userConfPath = this.getFileRealPath('ko.config.js');
21
21
  if ((0, fs_1.existsSync)(userConfPath)) {
22
- return userConfPath ? require(userConfPath) : {};
22
+ const userConf = require(userConfPath);
23
+ return userConf;
23
24
  }
24
25
  else {
25
26
  throw new Error('user config file not exist, please check it!');
@@ -31,7 +32,7 @@ class Config {
31
32
  dist: this.getFileRealPath('dist'),
32
33
  public: this.getFileRealPath('public'),
33
34
  html: this.getFileRealPath('public/index.html'),
34
- tsconfig: this.getFileRealPath('tsconfig.json')
35
+ tsconfig: this.getFileRealPath('tsconfig.json'),
35
36
  };
36
37
  }
37
38
  get isProductionEnv() {
@@ -24,7 +24,7 @@ describe('config instance', () => {
24
24
  dist: cwd + '/dist',
25
25
  public: cwd + '/public',
26
26
  html: cwd + '/public/index.html',
27
- tsconfig: cwd + '/tsconfig.json'
27
+ tsconfig: cwd + '/tsconfig.json',
28
28
  });
29
29
  });
30
30
  });
@@ -20,7 +20,7 @@ const extensions = [
20
20
  '.html',
21
21
  ];
22
22
  function getWebpackBaseConf(opts) {
23
- const { ts, hash } = opts;
23
+ const { ts = true, hash } = opts;
24
24
  const webpackBaseConf = {
25
25
  mode: config_1.default.isProductionEnv ? 'production' : 'development',
26
26
  target: 'web',
@@ -32,23 +32,24 @@ function getWebpackBaseConf(opts) {
32
32
  publicPath: '/',
33
33
  },
34
34
  module: {
35
- rules: (0, loaders_1.default)(opts),
35
+ rules: loaders_1.default,
36
36
  },
37
- plugins: (0, plugins_1.default)(opts),
37
+ plugins: (0, plugins_1.default)(),
38
38
  resolve: {
39
39
  extensions,
40
40
  plugins: [
41
- ts && new tsconfig_paths_webpack_plugin_1.default({
42
- configFile: config_1.default.defaultPaths.tsconfig
43
- })
44
- ].filter(Boolean)
41
+ ts &&
42
+ new tsconfig_paths_webpack_plugin_1.default({
43
+ configFile: config_1.default.defaultPaths.tsconfig,
44
+ }),
45
+ ].filter(Boolean),
45
46
  },
46
47
  performance: {
47
48
  hints: false,
48
49
  },
49
50
  cache: {
50
51
  type: 'filesystem',
51
- }
52
+ },
52
53
  };
53
54
  return webpackBaseConf;
54
55
  }
@@ -6,7 +6,5 @@ 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
- function getLoaders(opts) {
10
- return [...style_1.default, ...asset_1.default, ...(0, script_1.default)(opts.ts)];
11
- }
12
- exports.default = getLoaders;
9
+ const loaders = [...style_1.default, ...asset_1.default, ...script_1.default];
10
+ exports.default = loaders;
@@ -7,53 +7,45 @@ const getCacheIdentifier_1 = __importDefault(require("react-dev-utils/getCacheId
7
7
  const config_1 = __importDefault(require("../../utils/config"));
8
8
  const THREAD_LOADER = require.resolve('thread-loader');
9
9
  const BABEL_LOADER = require.resolve('babel-loader');
10
- function getScriptLoaders(supportTypescript) {
11
- let scriptLoader = [
12
- {
13
- test: /\.jsx?$/,
14
- include: config_1.default.defaultPaths.src,
15
- use: [
16
- THREAD_LOADER,
17
- {
18
- loader: BABEL_LOADER,
19
- options: {
20
- presets: [
21
- [
22
- require.resolve('babel-preset-ko-app'),
23
- {
24
- useAbsoluteRuntime: true,
25
- },
26
- ],
27
- ],
28
- babelrc: false,
29
- configFile: false,
30
- cacheIdentifier: (0, getCacheIdentifier_1.default)(config_1.default.isProductionEnv ? 'production' : '', ['babel-preset-ko-app', 'react-dev-utils', 'ko']),
31
- cacheDirectory: true,
32
- cacheCompression: false,
33
- compact: config_1.default.isProductionEnv,
34
- },
35
- },
36
- ],
10
+ const scriptLoader = [
11
+ {
12
+ test: /\.worker.[jt]s$/,
13
+ loader: 'worker-loader',
14
+ options: {
15
+ inline: 'fallback',
37
16
  },
38
- ];
39
- if (supportTypescript) {
40
- const TS_LOADER = require.resolve('ts-loader');
41
- const typescriptLoader = {
42
- test: /\.tsx?$/,
43
- use: [
44
- THREAD_LOADER,
45
- {
46
- loader: TS_LOADER,
47
- options: {
48
- transpileOnly: true,
49
- happyPackMode: true,
50
- allowTsInNodeModules: true
51
- },
17
+ },
18
+ {
19
+ test: /\.(t|j)sx?$/,
20
+ exclude: {
21
+ and: [/node_modules/],
22
+ not: [/dt-common/],
23
+ },
24
+ use: [
25
+ THREAD_LOADER,
26
+ {
27
+ loader: BABEL_LOADER,
28
+ options: {
29
+ presets: [
30
+ [
31
+ require.resolve('babel-preset-ko-app'),
32
+ {
33
+ useAbsoluteRuntime: true,
34
+ },
35
+ ],
36
+ ],
37
+ plugins: config_1.default.isProductionEnv
38
+ ? [require.resolve('react-refresh/babel')]
39
+ : [],
40
+ babelrc: false,
41
+ configFile: false,
42
+ cacheIdentifier: (0, getCacheIdentifier_1.default)(config_1.default.isProductionEnv ? 'production' : '', ['babel-preset-ko-app', 'react-dev-utils', 'ko']),
43
+ cacheDirectory: true,
44
+ cacheCompression: false,
45
+ compact: config_1.default.isProductionEnv,
52
46
  },
53
- ],
54
- };
55
- scriptLoader.push(typescriptLoader);
56
- }
57
- return scriptLoader;
58
- }
59
- exports.default = getScriptLoaders;
47
+ },
48
+ ],
49
+ },
50
+ ];
51
+ exports.default = scriptLoader;
@@ -10,7 +10,7 @@ const LESS_LOADER = require.resolve('less-loader');
10
10
  const SASS_LOADER = require.resolve('sass-loader');
11
11
  const POSTCSS_LOADER = require.resolve('postcss-loader');
12
12
  const styleLoader = {
13
- loader: mini_css_extract_plugin_1.loader
13
+ loader: mini_css_extract_plugin_1.loader,
14
14
  };
15
15
  const cssLoader = {
16
16
  loader: CSS_LOADER,
@@ -31,11 +31,7 @@ const postcssLoader = {
31
31
  const styleLoaders = [
32
32
  {
33
33
  test: /\.css$/,
34
- use: [
35
- styleLoader,
36
- cssLoader,
37
- postcssLoader,
38
- ],
34
+ use: [styleLoader, cssLoader, postcssLoader],
39
35
  },
40
36
  {
41
37
  test: /\.s[ac]ss$/,
@@ -6,45 +6,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const webpack_1 = require("webpack");
7
7
  const case_sensitive_paths_webpack_plugin_1 = __importDefault(require("case-sensitive-paths-webpack-plugin"));
8
8
  const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
9
- const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
9
+ const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
10
+ const webpackbar_1 = __importDefault(require("webpackbar"));
10
11
  const config_1 = __importDefault(require("../utils/config"));
11
- function getPlugins(opts) {
12
- const { ts } = opts;
13
- const { userConf, defaultPaths } = config_1.default;
14
- const publicPath = (userConf.output && userConf.output.publicPath) ? userConf.output.publicPath : '/';
12
+ function getPlugins() {
13
+ const { userConf } = config_1.default;
15
14
  let plugins = [
16
15
  new webpack_1.IgnorePlugin({
17
16
  resourceRegExp: /^\.\/locale$/,
18
17
  contextRegExp: /moment$/,
19
18
  }),
20
- new webpack_1.ProgressPlugin(),
21
19
  //TODO: check if mini-css-extract-plugin should use base name if enable HMR
22
20
  new mini_css_extract_plugin_1.default({
23
21
  filename: 'css/[name].[contenthash].css',
24
22
  chunkFilename: 'css/[id].[contenthash].css',
25
23
  }),
26
24
  new case_sensitive_paths_webpack_plugin_1.default(),
27
- new html_webpack_plugin_1.default({
28
- template: defaultPaths.html,
29
- title: 'Ko App',
30
- templateParameters: {
31
- configPath: `${publicPath}config/config.js`
32
- },
33
- inject: 'body'
34
- }),
25
+ new react_refresh_webpack_plugin_1.default(),
26
+ new webpackbar_1.default(),
35
27
  ];
36
- if (ts) {
37
- const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
38
- const typescriptPlugins = [
39
- new ForkTsCheckerWebpackPlugin({
40
- async: false,
41
- typescript: {
42
- configFile: defaultPaths.tsconfig,
43
- },
44
- }),
45
- ];
46
- plugins = plugins.concat(typescriptPlugins);
47
- }
48
28
  plugins = plugins.concat(userConf.plugins || []);
49
29
  if (config_1.default.isProductionEnv) {
50
30
  const { CleanWebpackPlugin } = require('clean-webpack-plugin');
@@ -52,7 +32,7 @@ function getPlugins(opts) {
52
32
  new CleanWebpackPlugin({
53
33
  verbose: false,
54
34
  dry: false,
55
- })
35
+ }),
56
36
  ];
57
37
  plugins.concat(prodPlugins);
58
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ko",
3
- "version": "5.2.2",
3
+ "version": "5.3.2",
4
4
  "description": "build & lint library",
5
5
  "keywords": [
6
6
  "ko",
@@ -34,58 +34,57 @@
34
34
  "scripts/*",
35
35
  "lib/*"
36
36
  ],
37
- "scripts": {
38
- "prepublishOnly": "rm -rf lib && tsc",
39
- "preinstall": "node scripts/preinstall.js",
40
- "debug": "tsc -w --sourceMap",
41
- "test": "jest",
42
- "build": "tsc"
43
- },
44
37
  "dependencies": {
45
- "autoprefixer": "^10.2.6",
46
- "babel-loader": "^8.2.2",
47
- "babel-preset-ko-app": "^1.0.0-alpha.1",
38
+ "@babel/core": "^7.17.5",
39
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.4",
40
+ "autoprefixer": "^10.4.2",
41
+ "babel-loader": "^8.2.3",
42
+ "babel-preset-ko-app": "^1.0.0",
48
43
  "case-sensitive-paths-webpack-plugin": "^2.4.0",
49
44
  "chalk": "^4.1.2",
50
- "clean-webpack-plugin": "3.0.0",
51
- "commander": "^8.1.0",
52
- "css-loader": "^5.2.6",
53
- "css-minimizer-webpack-plugin": "^3.0.1",
45
+ "clean-webpack-plugin": "4.0.0",
46
+ "commander": "^9.0.0",
47
+ "css-loader": "^6.6.0",
48
+ "css-minimizer-webpack-plugin": "^3.4.1",
54
49
  "detect-port": "^1.3.0",
55
- "esbuild-loader": "^2.16.0",
56
- "fork-ts-checker-webpack-plugin": "^6.2.10",
57
- "html-webpack-plugin": "^5.3.1",
58
- "inquirer": "^8.1.2",
59
- "ko-lints": "^1.0.0",
50
+ "esbuild-loader": "^2.18.0",
51
+ "inquirer": "^8.2.0",
60
52
  "less": "^3.13.1",
61
- "less-loader": "^9.0.0",
62
- "mini-css-extract-plugin": "^1.6.0",
63
- "postcss": "^8.3.0",
64
- "postcss-loader": "^5.3.0",
65
- "react-dev-utils": "^11.0.4",
66
- "sass": "^1.34.0",
67
- "sass-loader": "^11.1.1",
53
+ "less-loader": "^9.1.0",
54
+ "mini-css-extract-plugin": "^2.5.3",
55
+ "postcss": "^8.4.7",
56
+ "postcss-loader": "^6.2.1",
57
+ "react-dev-utils": "^12.0.0",
58
+ "react-refresh": "^0.11.0",
59
+ "sass": "^1.49.9",
60
+ "sass-loader": "^12.6.0",
68
61
  "thread-loader": "^3.0.4",
69
- "ts-loader": "^9.2.2",
70
- "tsconfig-paths-webpack-plugin": "^3.5.1",
71
- "webpack": "^5.50.0",
72
- "webpack-bundle-analyzer": "^4.4.2",
73
- "webpack-dev-server": "^3.11.2",
74
- "webpack-merge": "^5.8.0"
62
+ "tsconfig-paths-webpack-plugin": "^3.5.2",
63
+ "webpack": "^5.69.1",
64
+ "webpack-bundle-analyzer": "^4.5.0",
65
+ "webpack-dev-server": "^4.7.4",
66
+ "webpack-merge": "^5.8.0",
67
+ "webpackbar": "^5.0.2",
68
+ "worker-loader": "^3.0.8"
75
69
  },
76
70
  "devDependencies": {
77
71
  "@types/case-sensitive-paths-webpack-plugin": "^2.1.6",
78
- "@types/detect-port": "^1.3.1",
79
- "@types/inquirer": "^7.3.3",
80
- "@types/jest": "^27.0.2",
81
- "@types/mini-css-extract-plugin": "^2.2.0",
82
- "@types/react-dev-utils": "^9.0.7",
83
- "jest": "^27.2.5",
84
- "ts-jest": "^27.0.5",
85
- "typescript": "^4.4.4"
72
+ "@types/detect-port": "^1.3.2",
73
+ "@types/inquirer": "^8.2.0",
74
+ "@types/jest": "^27.4.1",
75
+ "@types/react-dev-utils": "^9.0.10",
76
+ "jest": "^27.5.1",
77
+ "ts-jest": "^27.1.3",
78
+ "typescript": "^4.6.2"
86
79
  },
87
80
  "engines": {
88
81
  "node": ">=10.13.0"
89
82
  },
90
- "gitHead": "3ce5dfb8cb7b50b758ebe6fa0ebfba7a89667a07"
91
- }
83
+ "scripts": {
84
+ "preinstall": "node scripts/preinstall.js",
85
+ "debug": "tsc -w --sourceMap",
86
+ "test": "jest",
87
+ "build": "tsc"
88
+ },
89
+ "readme": "# ko\n\nbuild & lint library\n"
90
+ }
@@ -16,7 +16,7 @@ if (LOCK_NODE_VERSION) {
16
16
  * webpack minor support version
17
17
  * @link https://webpack.js.org/migrate/5/#preparations
18
18
  */
19
- const webpack5SupportLeastVersion = 10.13;
19
+ const webpack5SupportLeastVersion = 10.13;
20
20
 
21
21
  if (majorAndMinorNodeVersion < webpack5SupportLeastVersion) {
22
22
  console.error(
@@ -49,4 +49,4 @@ if (FORCE_YARN_INSTALL) {
49
49
  }
50
50
  }
51
51
 
52
- err && process.exit(1);
52
+ err && process.exit(1);