ko 5.2.2-alpha.3 → 5.2.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.
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const webpack_1 = __importDefault(require("webpack"));
7
+ const esbuild_loader_1 = require("esbuild-loader");
7
8
  const creator_1 = require("./creator");
8
9
  const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
9
10
  class Build extends creator_1.WebpackCreator {
@@ -11,11 +12,16 @@ class Build extends creator_1.WebpackCreator {
11
12
  super(opts);
12
13
  }
13
14
  config() {
15
+ const { esbuild } = this.opts;
14
16
  const conf = {
15
17
  optimization: {
16
18
  minimizer: [
17
- new CssMinimizerPlugin()
18
- ]
19
+ !esbuild && new CssMinimizerPlugin(),
20
+ esbuild && new esbuild_loader_1.ESBuildMinifyPlugin({
21
+ target: 'es2015',
22
+ css: true
23
+ })
24
+ ].filter(Boolean)
19
25
  },
20
26
  plugins: [
21
27
  new webpack_1.default.optimize.SplitChunksPlugin({
@@ -51,7 +57,7 @@ class Build extends creator_1.WebpackCreator {
51
57
  }
52
58
  action() {
53
59
  //TODO: redefine stats
54
- webpack_1.default(this.config(), (error, stats) => {
60
+ (0, webpack_1.default)(this.config(), (error, stats) => {
55
61
  if (stats && stats.hasErrors()) {
56
62
  throw stats.toString({
57
63
  logging: 'warn',
@@ -17,16 +17,16 @@ class WebpackCreator extends Creator {
17
17
  this.baseConfig = this.initConfig(opts);
18
18
  }
19
19
  pluginsUnique(pluginNames) {
20
- return webpack_merge_1.unique('plugins', pluginNames, (plugin) => plugin.constructor && plugin.constructor.name);
20
+ return (0, webpack_merge_1.unique)('plugins', pluginNames, (plugin) => plugin.constructor && plugin.constructor.name);
21
21
  }
22
22
  initConfig(opts) {
23
- this.baseConfig = webpack_1.default(opts);
24
- return webpack_merge_1.mergeWithCustomize({
23
+ this.baseConfig = (0, webpack_1.default)(opts);
24
+ return (0, webpack_merge_1.mergeWithCustomize)({
25
25
  customizeArray: this.pluginsUnique(['HtmlWebpackPlugin']),
26
26
  })(this.baseConfig, config_1.default.userConf);
27
27
  }
28
28
  mergeConfig(conf) {
29
- return webpack_merge_1.merge(conf);
29
+ return (0, webpack_merge_1.merge)(conf);
30
30
  }
31
31
  successStdout(log) {
32
32
  console.log(chalk_1.default.green(log));
@@ -53,7 +53,7 @@ class Dev extends creator_1.WebpackCreator {
53
53
  message: `port: ${port} has been used,use new port ${newPort} instead?`,
54
54
  default: true,
55
55
  };
56
- const answer = await inquirer_1.prompt([question]);
56
+ const answer = await (0, inquirer_1.prompt)([question]);
57
57
  if (answer.changePort) {
58
58
  return newPort;
59
59
  }
@@ -62,7 +62,7 @@ class Dev extends creator_1.WebpackCreator {
62
62
  }
63
63
  }
64
64
  async checkPort(port) {
65
- const newPort = await detect_port_1.default(port);
65
+ const newPort = await (0, detect_port_1.default)(port);
66
66
  if (newPort === port) {
67
67
  return newPort;
68
68
  }
@@ -81,7 +81,7 @@ class Dev extends creator_1.WebpackCreator {
81
81
  if (!newPort)
82
82
  return;
83
83
  webpack_dev_server_1.default.addDevServerEntrypoints(this.config(), this.devSerConf());
84
- const compiler = webpack_1.default(this.config());
84
+ const compiler = (0, webpack_1.default)(this.config());
85
85
  const devServer = new webpack_dev_server_1.default(compiler, this.devSerConf());
86
86
  let isFirstCompile = true;
87
87
  compiler.hooks.done.tap('done', (stats) => {
package/lib/cli.js CHANGED
@@ -19,6 +19,7 @@ program
19
19
  .description('build project')
20
20
  .option('--hash', 'output file name with hash')
21
21
  .option('-t,--ts,--typescript', 'support typescript')
22
+ .option('-e,--esbuild', 'enable esbuild')
22
23
  .action((opts) => {
23
24
  const buildInstance = new build_1.default(opts);
24
25
  buildInstance.action();
@@ -36,5 +37,5 @@ program
36
37
  devInstance.action();
37
38
  });
38
39
  //attach lint features to program
39
- ko_lints_1.default(program);
40
+ (0, ko_lints_1.default)(program);
40
41
  program.parse();
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path_1 = require("path");
4
+ const fs_1 = require("fs");
4
5
  class Config {
5
6
  constructor() {
6
7
  this.cwd = process.cwd();
@@ -12,12 +13,17 @@ class Config {
12
13
  return Config.instance;
13
14
  }
14
15
  getFileRealPath(path) {
15
- return path_1.isAbsolute(path) ? path : path_1.resolve(this.cwd, path);
16
+ return (0, path_1.isAbsolute)(path) ? path : (0, path_1.resolve)(this.cwd, path);
16
17
  }
17
18
  //TODO: define userConf
18
19
  get userConf() {
19
20
  const userConfPath = this.getFileRealPath('ko.config.js');
20
- return userConfPath ? require(userConfPath) : {};
21
+ if ((0, fs_1.existsSync)(userConfPath)) {
22
+ return userConfPath ? require(userConfPath) : {};
23
+ }
24
+ else {
25
+ throw new Error('user config file not exist, please check it!');
26
+ }
21
27
  }
22
28
  get defaultPaths() {
23
29
  return {
@@ -0,0 +1,30 @@
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 config_1 = __importDefault(require("./config"));
7
+ console.log(typeof config_1.default.getFileRealPath);
8
+ describe('config instance', () => {
9
+ it('getFileRealPath should return absolute path', () => {
10
+ const absolutePath = '/foo/bar';
11
+ expect(config_1.default.getFileRealPath(absolutePath)).toBe(absolutePath);
12
+ const relativePath = 'ko.config.js';
13
+ expect(config_1.default.getFileRealPath(relativePath)).toBe(process.cwd() + '/' + relativePath);
14
+ });
15
+ it('userConf should throw', () => {
16
+ expect(() => {
17
+ config_1.default.userConf;
18
+ }).toThrow();
19
+ });
20
+ it('defaultPaths should ', () => {
21
+ const cwd = process.cwd();
22
+ expect(config_1.default.defaultPaths).toEqual({
23
+ src: cwd + '/src',
24
+ dist: cwd + '/dist',
25
+ public: cwd + '/public',
26
+ html: cwd + '/public/index.html',
27
+ tsconfig: cwd + '/tsconfig.json'
28
+ });
29
+ });
30
+ });
@@ -32,9 +32,9 @@ function getWebpackBaseConf(opts) {
32
32
  publicPath: '/',
33
33
  },
34
34
  module: {
35
- rules: loaders_1.default(opts),
35
+ rules: (0, loaders_1.default)(opts),
36
36
  },
37
- plugins: plugins_1.default(opts),
37
+ plugins: (0, plugins_1.default)(opts),
38
38
  resolve: {
39
39
  extensions,
40
40
  plugins: [
@@ -7,6 +7,6 @@ const style_1 = __importDefault(require("./style"));
7
7
  const asset_1 = __importDefault(require("./asset"));
8
8
  const script_1 = __importDefault(require("./script"));
9
9
  function getLoaders(opts) {
10
- return [...style_1.default, ...asset_1.default, ...script_1.default(opts.ts)];
10
+ return [...style_1.default, ...asset_1.default, ...(0, script_1.default)(opts.ts)];
11
11
  }
12
12
  exports.default = getLoaders;
@@ -27,7 +27,7 @@ function getScriptLoaders(supportTypescript) {
27
27
  ],
28
28
  babelrc: false,
29
29
  configFile: false,
30
- cacheIdentifier: getCacheIdentifier_1.default(config_1.default.isProductionEnv ? 'production' : '', ['babel-preset-ko-app', 'react-dev-utils', 'ko']),
30
+ cacheIdentifier: (0, getCacheIdentifier_1.default)(config_1.default.isProductionEnv ? 'production' : '', ['babel-preset-ko-app', 'react-dev-utils', 'ko']),
31
31
  cacheDirectory: true,
32
32
  cacheCompression: false,
33
33
  compact: config_1.default.isProductionEnv,
@@ -24,7 +24,7 @@ const postcssLoader = {
24
24
  options: {
25
25
  sourceMap: true,
26
26
  postcssOptions: {
27
- plugins: [autoprefixer_1.default()],
27
+ plugins: [(0, autoprefixer_1.default)()],
28
28
  },
29
29
  },
30
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ko",
3
- "version": "5.2.2-alpha.3",
3
+ "version": "5.2.2",
4
4
  "description": "build & lint library",
5
5
  "keywords": [
6
6
  "ko",
@@ -37,8 +37,9 @@
37
37
  "scripts": {
38
38
  "prepublishOnly": "rm -rf lib && tsc",
39
39
  "preinstall": "node scripts/preinstall.js",
40
- "build": "tsc",
41
- "debug": "tsc -w --sourceMap"
40
+ "debug": "tsc -w --sourceMap",
41
+ "test": "jest",
42
+ "build": "tsc"
42
43
  },
43
44
  "dependencies": {
44
45
  "autoprefixer": "^10.2.6",
@@ -51,10 +52,11 @@
51
52
  "css-loader": "^5.2.6",
52
53
  "css-minimizer-webpack-plugin": "^3.0.1",
53
54
  "detect-port": "^1.3.0",
55
+ "esbuild-loader": "^2.16.0",
54
56
  "fork-ts-checker-webpack-plugin": "^6.2.10",
55
57
  "html-webpack-plugin": "^5.3.1",
56
58
  "inquirer": "^8.1.2",
57
- "ko-lints": "^1.0.0-alpha.2",
59
+ "ko-lints": "^1.0.0",
58
60
  "less": "^3.13.1",
59
61
  "less-loader": "^9.0.0",
60
62
  "mini-css-extract-plugin": "^1.6.0",
@@ -75,12 +77,15 @@
75
77
  "@types/case-sensitive-paths-webpack-plugin": "^2.1.6",
76
78
  "@types/detect-port": "^1.3.1",
77
79
  "@types/inquirer": "^7.3.3",
80
+ "@types/jest": "^27.0.2",
78
81
  "@types/mini-css-extract-plugin": "^2.2.0",
79
82
  "@types/react-dev-utils": "^9.0.7",
80
- "typescript": "^4.3.5"
83
+ "jest": "^27.2.5",
84
+ "ts-jest": "^27.0.5",
85
+ "typescript": "^4.4.4"
81
86
  },
82
87
  "engines": {
83
88
  "node": ">=10.13.0"
84
89
  },
85
- "gitHead": "bcc192273ff455b110d0804eb80b6a714122ff60"
90
+ "gitHead": "3ce5dfb8cb7b50b758ebe6fa0ebfba7a89667a07"
86
91
  }