@modern-js/babel-compiler 1.2.1 → 1.2.4

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 (39) hide show
  1. package/.eslintrc.js +8 -0
  2. package/CHANGELOG.md +33 -0
  3. package/dist/js/modern/buildWatch.js +4 -4
  4. package/dist/js/modern/getFinalOption.js +1 -1
  5. package/dist/js/modern/type.js +0 -1
  6. package/dist/js/node/buildWatch.js +4 -4
  7. package/dist/js/node/getFinalOption.js +2 -6
  8. package/dist/js/node/type.js +0 -5
  9. package/dist/types/buildWatch.d.ts +1 -1
  10. package/dist/types/getFinalOption.d.ts +2 -2
  11. package/dist/types/type.d.ts +5 -5
  12. package/jest.config.js +0 -1
  13. package/modern.config.js +0 -1
  14. package/package.json +4 -8
  15. package/tests/.eslintrc.js +0 -6
  16. package/tests/build.test.ts +0 -122
  17. package/tests/buildWatch.test.ts +0 -251
  18. package/tests/compiler.test.ts +0 -112
  19. package/tests/compilerErrorResult.test.ts +0 -119
  20. package/tests/constants.test.ts +0 -12
  21. package/tests/defaults.test.ts +0 -29
  22. package/tests/fixtures/build/src/error +0 -1
  23. package/tests/fixtures/build/src/error1 +0 -1
  24. package/tests/fixtures/build/src/far.js +0 -0
  25. package/tests/fixtures/build/src/index.js +0 -0
  26. package/tests/fixtures/buildWatch/src/error +0 -2
  27. package/tests/fixtures/buildWatch/src/index.js +0 -0
  28. package/tests/fixtures/compiler/src/index.js +0 -2
  29. package/tests/fixtures/getFinalOption/sourceDir/bar.js +0 -0
  30. package/tests/fixtures/getFinalOption/watchDir/far.js +0 -0
  31. package/tests/fixtures/getFinalOption/watchDir/foo.jsx +0 -0
  32. package/tests/fixtures/lib/src/index.js +0 -0
  33. package/tests/fixtures/resolveSourceMap/src/index.js +0 -2
  34. package/tests/fixtures/utils/far +0 -2
  35. package/tests/getFinalOption.test.ts +0 -108
  36. package/tests/index.test.ts +0 -89
  37. package/tests/tsconfig.json +0 -13
  38. package/tests/utils.test.ts +0 -20
  39. package/tests/validate.test.ts +0 -68
package/.eslintrc.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['@modern-js'],
4
+ parserOptions: {
5
+ tsconfigRootDir: __dirname,
6
+ project: ['./tsconfig.json'],
7
+ },
8
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @modern-js/babel-compiler
2
2
 
3
+ ## 1.2.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 0e0537005: fix: unlock @babel/core version
8
+ - 69a728375: fix: remove exports.jsnext:source after publish
9
+ - Updated dependencies [cd7346b0d]
10
+ - Updated dependencies [69a728375]
11
+ - @modern-js/utils@1.7.2
12
+
13
+ ## 1.2.3
14
+
15
+ ### Patch Changes
16
+
17
+ - 6cffe99d: chore:
18
+ remove react eslint rules for `modern-js` rule set.
19
+ add .eslintrc for each package to speed up linting
20
+ - 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
21
+ - 60f7d8bf: feat: add tests dir to npmignore
22
+ - Updated dependencies [b8599d09]
23
+ - Updated dependencies [60f7d8bf]
24
+ - Updated dependencies [3bf4f8b0]
25
+ - @modern-js/utils@1.5.0
26
+
27
+ ## 1.2.2
28
+
29
+ ### Patch Changes
30
+
31
+ - 55e18278: chore: remove unused dependencies and devDependencies
32
+ - Updated dependencies [4c792f68]
33
+ - Updated dependencies [a7f42f48]
34
+ - @modern-js/utils@1.3.3
35
+
3
36
  ## 1.2.1
4
37
 
5
38
  ### Patch Changes
@@ -42,16 +42,16 @@ export const runBuildWatch = async (option, babelConfig = {}, emitter) => {
42
42
  quiet
43
43
  } = option; // 第一次正常构建
44
44
 
45
- const fisrtBuildResult = await build(option, babelConfig);
45
+ const firstBuildResult = await build(option, babelConfig);
46
46
  const {
47
47
  code
48
- } = fisrtBuildResult;
48
+ } = firstBuildResult;
49
49
 
50
50
  if (code === 1) {
51
- errorResult.init(fisrtBuildResult);
51
+ errorResult.init(firstBuildResult);
52
52
  emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
53
53
  } else {
54
- emitter.emit(BuildWatchEvent.firstCompiler, fisrtBuildResult);
54
+ emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
55
55
  }
56
56
 
57
57
  return watch(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  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; }
6
6
 
7
- import * as glob from 'glob';
7
+ import { glob } from '@modern-js/utils';
8
8
  import { DEFAULT_EXTENSIONS } from '@babel/core';
9
9
  import { mergeDefaultOption } from "./defaults";
10
10
  export const getGlobPattern = (dir, extensions) => {
@@ -1 +0,0 @@
1
- export {};
@@ -63,16 +63,16 @@ const runBuildWatch = async (option, babelConfig = {}, emitter) => {
63
63
  quiet
64
64
  } = option; // 第一次正常构建
65
65
 
66
- const fisrtBuildResult = await (0, _build.build)(option, babelConfig);
66
+ const firstBuildResult = await (0, _build.build)(option, babelConfig);
67
67
  const {
68
68
  code
69
- } = fisrtBuildResult;
69
+ } = firstBuildResult;
70
70
 
71
71
  if (code === 1) {
72
- errorResult.init(fisrtBuildResult);
72
+ errorResult.init(firstBuildResult);
73
73
  emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
74
74
  } else {
75
- emitter.emit(BuildWatchEvent.firstCompiler, fisrtBuildResult);
75
+ emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
76
76
  }
77
77
 
78
78
  return (0, _utils.watch)(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({
@@ -5,16 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getGlobPattern = exports.getFinalExtensions = exports.getFinalCompilerOption = exports.getFilesFromDir = void 0;
7
7
 
8
- var glob = _interopRequireWildcard(require("glob"));
8
+ var _utils = require("@modern-js/utils");
9
9
 
10
10
  var _core = require("@babel/core");
11
11
 
12
12
  var _defaults = require("./defaults");
13
13
 
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); }
15
-
16
- 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; }
17
-
18
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; }
19
15
 
20
16
  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; }
@@ -56,7 +52,7 @@ const getFilesFromDir = ({
56
52
  }) => {
57
53
  let globFindFilenames = [];
58
54
  const globPattern = getGlobPattern(dir, _finalExt);
59
- globFindFilenames = glob.sync(globPattern, {
55
+ globFindFilenames = _utils.glob.sync(globPattern, {
60
56
  ignore: _ignore
61
57
  });
62
58
  return globFindFilenames;
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import * as Event from 'events';
3
- import { FSWatcher } from 'chokidar';
3
+ import { FSWatcher } from '@modern-js/utils';
4
4
  import type { IFinaleCompilerOptions, BabelOptions } from './type';
5
5
  export declare const BuildWatchEvent: {
6
6
  firstCompiler: string;
@@ -1,4 +1,4 @@
1
- import type { IOptions } from 'glob';
1
+ import { GlobOptions } from '@modern-js/utils';
2
2
  import { Extensions, ExtensionsFunc, ICompilerOptions, IFinaleCompilerOptions } from './type';
3
3
  export declare const getGlobPattern: (dir: string, extensions: Extensions) => string;
4
4
  export declare const getFinalExtensions: (extensions: Extensions | ExtensionsFunc | undefined) => string[];
@@ -9,6 +9,6 @@ export declare const getFilesFromDir: ({
9
9
  }: {
10
10
  dir: string;
11
11
  finalExt?: string[] | undefined;
12
- ignore?: IOptions['ignore'];
12
+ ignore?: GlobOptions['ignore'];
13
13
  }) => string[];
14
14
  export declare const getFinalCompilerOption: (option: ICompilerOptions) => IFinaleCompilerOptions;
@@ -1,5 +1,5 @@
1
- import { TransformOptions } from '@babel/core';
2
- import type { IOptions } from 'glob';
1
+ import type { TransformOptions } from '@babel/core';
2
+ import type { GlobOptions } from '@modern-js/utils';
3
3
  export declare type BabelOptions = TransformOptions;
4
4
  export declare type Extensions = string[];
5
5
  export declare type ExtensionsFunc = (defaultExtensions: Extensions) => Extensions;
@@ -13,7 +13,7 @@ export interface ICompilerOptions {
13
13
  extensions?: Extensions | ExtensionsFunc;
14
14
  filenames?: string[];
15
15
  distFileExtMap?: Record<string, string>;
16
- ignore?: IOptions['ignore'];
16
+ ignore?: GlobOptions['ignore'];
17
17
  quiet?: boolean;
18
18
  verbose?: boolean;
19
19
  clean?: boolean;
@@ -28,7 +28,7 @@ export interface ICompilerOptionsWithDefault {
28
28
  extensions: Extensions | ExtensionsFunc;
29
29
  filenames: string[];
30
30
  distFileExtMap?: Record<string, string>;
31
- ignore: IOptions['ignore'];
31
+ ignore: GlobOptions['ignore'];
32
32
  quiet?: boolean;
33
33
  verbose?: boolean;
34
34
  clean?: boolean;
@@ -36,7 +36,7 @@ export interface ICompilerOptionsWithDefault {
36
36
  export interface IFinaleCompilerOptions {
37
37
  rootDir: string;
38
38
  filenames: string[];
39
- ignore?: IOptions['ignore'];
39
+ ignore?: GlobOptions['ignore'];
40
40
  enableVirtualDist?: boolean;
41
41
  distDir: string;
42
42
  watchDir?: string;
package/jest.config.js CHANGED
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
2
2
 
3
3
  /** @type {import('@jest/types').Config.InitialOptions} */
4
4
  module.exports = {
5
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
5
  ...sharedConfig,
7
6
  rootDir: __dirname,
8
7
  };
package/modern.config.js CHANGED
@@ -1,7 +1,6 @@
1
1
  /** @type {import('@modern-js/module-tools').UserConfig} */
2
2
  module.exports = {
3
3
  output: {
4
- // enableTsChecker: true,
5
4
  disableSourceMap: true,
6
5
  },
7
6
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.1",
14
+ "version": "1.2.4",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -28,11 +28,9 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@babel/core": "7.16.7",
31
+ "@babel/core": "^7.17.0",
32
32
  "@babel/runtime": "^7",
33
- "@modern-js/utils": "^1.2.2",
34
- "chokidar": "^3.5.2",
35
- "glob": "^7.1.6"
33
+ "@modern-js/utils": "^1.7.2"
36
34
  },
37
35
  "devDependencies": {
38
36
  "@babel/plugin-transform-classes": "^7.14.9",
@@ -41,7 +39,6 @@
41
39
  "@types/glob": "^7.1.4",
42
40
  "@types/jest": "^26",
43
41
  "@types/node": "^14",
44
- "jest-jasmine2": "^27.2.2",
45
42
  "typescript": "^4",
46
43
  "@scripts/build": "0.0.0",
47
44
  "jest": "^27",
@@ -55,8 +52,7 @@
55
52
  },
56
53
  "publishConfig": {
57
54
  "registry": "https://registry.npmjs.org/",
58
- "access": "public",
59
- "types": "./dist/types/index.d.ts"
55
+ "access": "public"
60
56
  },
61
57
  "scripts": {
62
58
  "new": "modern new",
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
@@ -1,122 +0,0 @@
1
- import * as path from 'path';
2
- import * as glob from 'glob';
3
- import { fs, logger } from '@modern-js/utils';
4
- import { build } from '../src/build';
5
-
6
- const projectDir = path.join(__dirname, './fixtures/build');
7
- const srcDir = path.join(projectDir, 'src');
8
- const distDir = path.join(projectDir, 'dist');
9
-
10
- const originalLogInfo = logger.info;
11
- const originalLogError = logger.error;
12
-
13
- describe('test build', () => {
14
- let testLogs: any[] = [];
15
- const mockedLogInfo = (s: string | number | Error | undefined) =>
16
- testLogs.push(s);
17
- beforeEach(() => {
18
- logger.info = mockedLogInfo;
19
- logger.error = mockedLogInfo;
20
- });
21
-
22
- it('normal build and success', async () => {
23
- const filenames = [path.join(srcDir, './index.js')];
24
- await build({ rootDir: srcDir, filenames, distDir });
25
- const globFindFiles = glob.sync(`${distDir}/**/*.js`);
26
- expect(globFindFiles.length).toBe(1);
27
- });
28
-
29
- it('build with enableVirtualDist and success', async () => {
30
- const filenames = [path.join(srcDir, './index.js')];
31
- const ret_1 = await build({
32
- rootDir: srcDir,
33
- filenames,
34
- distDir,
35
- });
36
- expect(ret_1.code).toBe(0);
37
- expect(ret_1.message.includes('Successfully compiled')).toBe(true);
38
- expect(ret_1.virtualDists?.length).toBe(0);
39
-
40
- const ret = await build({
41
- rootDir: srcDir,
42
- filenames,
43
- distDir,
44
- enableVirtualDist: true,
45
- });
46
-
47
- expect(ret.code).toBe(0);
48
- expect(ret.virtualDists?.length).toBe(1);
49
- });
50
-
51
- it('build with quiet and success', async () => {
52
- const filenames = [path.join(srcDir, './index.js')];
53
- await build({
54
- rootDir: srcDir,
55
- filenames,
56
- distDir,
57
- });
58
- expect(testLogs.length).toBe(1);
59
- testLogs = [];
60
-
61
- await build({
62
- rootDir: srcDir,
63
- filenames,
64
- distDir,
65
- quiet: true,
66
- });
67
- expect(testLogs.length).toBe(0);
68
- });
69
-
70
- it('build with clean and success', async () => {
71
- fs.ensureFileSync(path.join(distDir, './test1.js'));
72
- fs.ensureFileSync(path.join(distDir, './test2.js'));
73
- const filenames = [path.join(srcDir, './index.js')];
74
- await build({
75
- rootDir: srcDir,
76
- filenames,
77
- distDir,
78
- clean: true,
79
- });
80
- const globFindFiles = glob.sync(`${distDir}/**/*.js`);
81
- expect(globFindFiles.length).toBe(1);
82
- });
83
-
84
- it('build multiple files and success', async () => {
85
- const filenames = [
86
- path.join(srcDir, './index.js'),
87
- path.join(srcDir, './far.js'),
88
- ];
89
- const ret = await build({ rootDir: srcDir, filenames, distDir });
90
- expect(ret.code).toBe(0);
91
- expect(ret.message.includes('files')).toBe(true);
92
- expect((testLogs[0] as string).includes('files')).toBe(true);
93
- });
94
-
95
- it('build and fail', async () => {
96
- const filenames = [path.join(srcDir, './error')];
97
- const ret = await build({ rootDir: srcDir, filenames, distDir });
98
- expect(ret.code).toBe(1);
99
- expect(ret.messageDetails?.length).toBe(1);
100
- expect(ret.message.includes('Compilation failure')).toBe(true);
101
- expect(testLogs.length).toBe(1);
102
- expect((testLogs[0] as string).includes('Compilation failure')).toBe(true);
103
- });
104
-
105
- it('build multiple files and fail', async () => {
106
- const filenames = [
107
- path.join(srcDir, './error'),
108
- path.join(srcDir, './error1'),
109
- ];
110
- const ret = await build({ rootDir: srcDir, filenames, distDir });
111
- expect(ret.code).toBe(1);
112
- expect(ret.message.includes('files')).toBe(true);
113
- expect((testLogs[0] as string).includes('files')).toBe(true);
114
- });
115
-
116
- afterEach(() => {
117
- logger.info = originalLogInfo;
118
- logger.error = originalLogError;
119
- testLogs = [];
120
- fs.removeSync(distDir);
121
- });
122
- });
@@ -1,251 +0,0 @@
1
- import * as path from 'path';
2
- import { fs, logger } from '@modern-js/utils';
3
- import {
4
- buildWatch,
5
- BuildWatchEmitter,
6
- runBuildWatch,
7
- BuildWatchEvent,
8
- } from '../src/buildWatch';
9
- import { ICompilerResult } from '../src/type';
10
-
11
- const projectDir = path.join(__dirname, './fixtures/buildWatch');
12
- const srcDir = path.join(projectDir, 'src');
13
- const distDir = path.join(projectDir, 'dist');
14
-
15
- const originalLogInfo = logger.info;
16
- const originalLogError = logger.error;
17
-
18
- describe('test build watch', () => {
19
- let testLogs: any[] = [];
20
- const mockedLogInfo = (s: string | number | Error | undefined) =>
21
- testLogs.push(s);
22
- beforeEach(() => {
23
- logger.info = mockedLogInfo;
24
- logger.error = mockedLogInfo;
25
- });
26
-
27
- it('class BuildWatchEmitter', async () => {
28
- let run = false;
29
- const emitter = new BuildWatchEmitter();
30
- emitter.setInitFn(() => {
31
- run = true;
32
- });
33
- await emitter.watch();
34
- expect(run).toBe(true);
35
-
36
- const emitter_1 = new BuildWatchEmitter();
37
- emitter_1.setInitFn(true as any);
38
- const ret = await emitter_1.watch();
39
- expect(ret).toBe(null);
40
- });
41
-
42
- it('runBuildWatch and success', async () => {
43
- let done: any;
44
- const promise = new Promise(resolve => (done = resolve));
45
- let compiling = false;
46
- const emitter = new BuildWatchEmitter();
47
- emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
48
- expect(result.code).toBe(0);
49
- });
50
- emitter.on(BuildWatchEvent.compiling, () => {
51
- expect(compiling).toBe(true);
52
- });
53
- emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
54
- expect(result.code).toBe(0);
55
- watcher.close();
56
- done();
57
- });
58
- const filenames = [path.join(srcDir, 'index.js')];
59
- compiling = true;
60
- const watcher = await runBuildWatch(
61
- { rootDir: srcDir, filenames, distDir, watchDir: srcDir },
62
- {},
63
- emitter,
64
- );
65
- compiling = false;
66
- watcher.on('ready', () => {
67
- fs.ensureFileSync(path.join(srcDir, 'far.js'));
68
- compiling = true;
69
- });
70
- return promise;
71
- });
72
-
73
- it('runBuildWatch and fail', async () => {
74
- let done: any;
75
- const promise = new Promise(resolve => (done = resolve));
76
- const emitter = new BuildWatchEmitter();
77
- emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
78
- expect(result.code).toBe(1);
79
- expect(result.messageDetails?.length).toBe(1);
80
- });
81
- emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
82
- expect(result.code).toBe(1);
83
- expect(result.messageDetails?.length).toBe(2);
84
- watcher.close();
85
- done();
86
- });
87
- const filenames = [path.join(srcDir, 'error')];
88
- const watcher = await runBuildWatch(
89
- { rootDir: srcDir, filenames, distDir, watchDir: srcDir },
90
- {},
91
- emitter,
92
- );
93
- watcher.on('ready', () => {
94
- fs.ensureFileSync(path.join(srcDir, 'error1.js'));
95
- fs.writeFileSync(path.join(srcDir, 'error1.js'), 'conta a = 1');
96
- });
97
- return promise;
98
- });
99
-
100
- it('buildWatch and success', async () => {
101
- let done: any;
102
- const promise = new Promise(resolve => (done = resolve));
103
- const emitter = buildWatch({
104
- rootDir: srcDir,
105
- watchDir: srcDir,
106
- filenames: [path.join(srcDir, 'index.js')],
107
- distDir,
108
- enableVirtualDist: true,
109
- clean: true,
110
- });
111
- let compiling = false;
112
- emitter.on(BuildWatchEvent.compiling, () => {
113
- expect(compiling).toBe(true);
114
- });
115
- emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
116
- expect(result.code).toBe(0);
117
- expect(result.virtualDists?.length).toBe(1);
118
- });
119
- emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
120
- expect(result.code).toBe(0);
121
- expect(result.virtualDists?.length).toBe(1);
122
- expect(result.virtualDists![0].distPath.includes('far.js')).toBe(true);
123
- watcher?.close();
124
- done();
125
- });
126
-
127
- compiling = true;
128
- const watcher = await emitter.watch();
129
- compiling = false;
130
- if (watcher) {
131
- watcher.on('ready', () => {
132
- fs.ensureFileSync(path.join(srcDir, 'far.js'));
133
- compiling = true;
134
- });
135
- }
136
- return promise;
137
- });
138
-
139
- it('buildWatch and fail', async () => {
140
- let done: any;
141
- const promise = new Promise(resolve => (done = resolve));
142
- const emitter = buildWatch({
143
- rootDir: srcDir,
144
- watchDir: srcDir,
145
- filenames: [path.join(srcDir, 'error')],
146
- distDir,
147
- enableVirtualDist: true,
148
- clean: true,
149
- });
150
- let compiling = false;
151
- emitter.on(BuildWatchEvent.compiling, () => {
152
- expect(compiling).toBe(true);
153
- });
154
- emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
155
- expect(result.code).toBe(1);
156
- expect(result.messageDetails?.length).toBe(1);
157
- });
158
- emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
159
- expect(result.code).toBe(1);
160
- expect(result.messageDetails?.length).toBe(2);
161
- watcher?.close();
162
- done();
163
- });
164
-
165
- compiling = true;
166
- const watcher = await emitter.watch();
167
- compiling = false;
168
- if (watcher) {
169
- watcher.on('ready', () => {
170
- fs.ensureFileSync(path.join(srcDir, 'error1.js'));
171
- fs.writeFileSync(path.join(srcDir, 'error1.js'), 'cast a = 1;');
172
- compiling = true;
173
- });
174
- }
175
- return promise;
176
- });
177
-
178
- it('buildWatch and remove file', async () => {
179
- let done: any;
180
- const promise = new Promise(resolve => (done = resolve));
181
- const emitter = buildWatch({
182
- rootDir: srcDir,
183
- watchDir: srcDir,
184
- filenames: [path.join(srcDir, 'index.js')],
185
- distDir,
186
- enableVirtualDist: true,
187
- clean: true,
188
- quiet: true,
189
- });
190
-
191
- emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
192
- expect(result.code).toBe(0);
193
- expect(result.message.includes('remove file')).toBe(true);
194
- expect(result.removeFiles?.length).toBe(1);
195
- watcher?.close();
196
- done();
197
- });
198
-
199
- fs.ensureFileSync(path.join(srcDir, 'far.js'));
200
- const watcher = await emitter.watch();
201
-
202
- if (watcher) {
203
- watcher.on('ready', () => {
204
- fs.removeSync(path.join(srcDir, 'far.js'));
205
- });
206
- }
207
- return promise;
208
- });
209
-
210
- it('buildWatch and reRight file', async () => {
211
- let done: any;
212
- const promise = new Promise(resolve => (done = resolve));
213
- fs.ensureFileSync(path.join(srcDir, 'error1.js'));
214
- fs.writeFileSync(path.join(srcDir, 'error1.js'), 'cast a = 1;');
215
- const emitter = buildWatch({
216
- rootDir: srcDir,
217
- watchDir: srcDir,
218
- filenames: [path.join(srcDir, 'error'), path.join(srcDir, 'error1.js')],
219
- distDir,
220
- enableVirtualDist: true,
221
- clean: true,
222
- });
223
-
224
- emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
225
- expect(result.code).toBe(1);
226
- expect(result.messageDetails?.length).toBe(2);
227
- });
228
- emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
229
- expect(result.code).toBe(1);
230
- expect(result.messageDetails?.length).toBe(1);
231
- watcher?.close();
232
- done();
233
- });
234
-
235
- const watcher = await emitter.watch();
236
- if (watcher) {
237
- watcher.on('ready', () => {
238
- fs.writeFileSync(path.join(srcDir, 'error1.js'), 'const a = 1;');
239
- });
240
- }
241
- return promise;
242
- });
243
-
244
- afterEach(() => {
245
- logger.info = originalLogInfo;
246
- logger.error = originalLogError;
247
- testLogs = [];
248
- fs.removeSync(path.join(srcDir, 'far.js'));
249
- fs.removeSync(path.join(srcDir, 'error1.js'));
250
- });
251
- });
@@ -1,112 +0,0 @@
1
- import * as path from 'path';
2
- import { fs } from '@modern-js/utils';
3
- import * as babel from '@babel/core';
4
- import {
5
- isRes,
6
- getDistFilePath,
7
- resolveSourceMap,
8
- compiler,
9
- } from '../src/compiler';
10
- import { defaultDistFileExtMap } from '../src/constants';
11
-
12
- describe('compiler', () => {
13
- it('isRes', () => {
14
- const res_1 = isRes({ code: '' });
15
- expect(res_1).toBe(true);
16
- const res_2 = isRes(null);
17
- expect(res_2).toBe(false);
18
- });
19
-
20
- it('getDistFilePath', () => {
21
- const distpath_1 = getDistFilePath({
22
- rootDir: '/project',
23
- filepath: '/project/src/b.js',
24
- distDir: '/project/dist',
25
- extMap: defaultDistFileExtMap,
26
- });
27
- expect(path.normalize(distpath_1)).toBe(
28
- path.normalize('/project/dist/src/b.js'),
29
- );
30
-
31
- const distpath_2 = getDistFilePath({
32
- rootDir: '/project/src',
33
- filepath: '/project/src/b.js',
34
- distDir: '/project/dist',
35
- extMap: defaultDistFileExtMap,
36
- });
37
- expect(path.normalize(distpath_2)).toBe(
38
- path.normalize('/project/dist/b.js'),
39
- );
40
- });
41
-
42
- it('resolveSourceMap', () => {
43
- const projectDir = path.join(__dirname, './fixtures/resolveSourceMap');
44
- fs.removeSync(path.join(projectDir, 'dist'));
45
- const babelRes = babel.transformFileSync(
46
- path.join(projectDir, 'src/index.js'),
47
- { sourceMaps: true, cwd: projectDir },
48
- );
49
- const distFilePath = path.join(projectDir, 'dist/far.js');
50
- const sourcemap_1 = resolveSourceMap({
51
- babelRes: babelRes as babel.BabelFileResult,
52
- sourceFilePath: path.join(projectDir, 'src/index.js'),
53
- distFilePath,
54
- enableVirtualDist: true,
55
- });
56
- expect(sourcemap_1.sourceMapPath).toBe(
57
- path.join(projectDir, 'dist/far.js.map'),
58
- );
59
- // TODO test sourcemap content
60
-
61
- const sourcemap_2 = resolveSourceMap({
62
- babelRes: babelRes as babel.BabelFileResult,
63
- sourceFilePath: path.join(projectDir, 'src/index.js'),
64
- distFilePath,
65
- });
66
- expect(fs.readFileSync(sourcemap_2.sourceMapPath, 'utf-8')).toBe(
67
- sourcemap_2.sourcemap,
68
- );
69
- });
70
-
71
- it('compiler', () => {
72
- const projectPath = path.join(__dirname, './fixtures/compiler');
73
- const sourceFilePath = path.join(projectPath, './src/index.js');
74
- const distPath = path.join(projectPath, 'dist');
75
-
76
- compiler({
77
- rootDir: path.join(projectPath, 'src'),
78
- filepath: sourceFilePath,
79
- });
80
- expect(fs.existsSync(path.join(distPath, 'index.js'))).toBe(true);
81
- fs.removeSync(distPath);
82
-
83
- const dist1Path = path.join(projectPath, 'dist1');
84
- compiler({
85
- rootDir: path.join(projectPath, 'src'),
86
- filepath: sourceFilePath,
87
- distDir: dist1Path,
88
- babelConfig: { sourceMaps: true },
89
- });
90
- expect(fs.existsSync(dist1Path)).toBe(true);
91
- fs.removeSync(dist1Path);
92
-
93
- compiler({
94
- rootDir: path.join(projectPath, 'src'),
95
- filepath: sourceFilePath,
96
- babelConfig: { sourceMaps: true },
97
- });
98
- expect(fs.existsSync(path.join(distPath, 'index.js'))).toBe(true);
99
- expect(fs.existsSync(path.join(distPath, 'index.js.map'))).toBe(true);
100
- fs.removeSync(distPath);
101
-
102
- compiler({
103
- rootDir: path.join(projectPath, 'src'),
104
- filepath: sourceFilePath,
105
- enableVirtualDist: true,
106
- babelConfig: { sourceMaps: true },
107
- });
108
- expect(fs.existsSync(path.join(distPath, 'index.js'))).toBe(false);
109
- expect(fs.existsSync(path.join(distPath, 'index.js.map'))).toBe(false);
110
- fs.removeSync(distPath);
111
- });
112
- });
@@ -1,119 +0,0 @@
1
- import { CompilerErrorResult } from '../src/compilerErrorResult';
2
-
3
- describe('CompilerErrorResult Class', () => {
4
- it('call constructor without params', () => {
5
- const cer_1 = new CompilerErrorResult();
6
- expect(Array.isArray(cer_1._messageDetails)).toBe(true);
7
- expect(cer_1._messageDetails.length).toBe(0);
8
- });
9
-
10
- it('call constructor with params', () => {
11
- const cer_1 = new CompilerErrorResult({ code: 1, message: 'fail' });
12
- expect(Array.isArray(cer_1._messageDetails)).toBe(true);
13
- expect(cer_1._messageDetails.length).toBe(0);
14
-
15
- const cer_2 = new CompilerErrorResult({
16
- code: 1,
17
- message: 'fail',
18
- messageDetails: [{ content: 'error', filename: 'far.js' }],
19
- });
20
- expect(Array.isArray(cer_1._messageDetails)).toBe(true);
21
- expect(cer_2._messageDetails.length).toBe(1);
22
- });
23
-
24
- it('use init', () => {
25
- const cer_1 = new CompilerErrorResult();
26
- cer_1.init({ code: 1, message: 'fail' });
27
- expect(Array.isArray(cer_1._messageDetails)).toBe(true);
28
- expect(cer_1._messageDetails.length).toBe(0);
29
-
30
- const cer_2 = new CompilerErrorResult();
31
- cer_2.init({
32
- code: 1,
33
- message: 'fail',
34
- messageDetails: [{ content: 'error', filename: 'far.js' }],
35
- });
36
- expect(Array.isArray(cer_1._messageDetails)).toBe(true);
37
- expect(cer_2._messageDetails.length).toBe(1);
38
- });
39
-
40
- it('update diff messageDetails', () => {
41
- const cer_1 = new CompilerErrorResult({ code: 1, message: 'fail' });
42
- const firstCount = cer_1._messageDetails.length;
43
- cer_1.update([{ content: 'error', filename: 'far.js' }]);
44
- const secondCount = cer_1._messageDetails.length;
45
- cer_1.update([{ content: 'error', filename: 'bar.js' }]);
46
- const thirdCount = cer_1._messageDetails.length;
47
- expect(firstCount).toBe(0);
48
- expect(secondCount).toBe(1);
49
- expect(thirdCount).toBe(2);
50
- });
51
-
52
- it('update same messageDetails', () => {
53
- const cer_1 = new CompilerErrorResult({ code: 1, message: 'fail' });
54
- const firstCount = cer_1._messageDetails.length;
55
- cer_1.update([{ content: 'error-1', filename: 'far.js' }]);
56
- const secondCount = cer_1._messageDetails.length;
57
- cer_1.update([{ content: 'error-2', filename: 'far.js' }]);
58
- const thirdCount = cer_1._messageDetails.length;
59
- expect(firstCount).toBe(0);
60
- expect(secondCount).toBe(1);
61
- expect(thirdCount).toBe(1);
62
- });
63
-
64
- it('remove by file name', () => {
65
- const cer_1 = new CompilerErrorResult({
66
- code: 1,
67
- message: 'fail',
68
- messageDetails: [{ content: 'error-1', filename: 'far.js' }],
69
- });
70
- const firstCount = cer_1._messageDetails.length;
71
- cer_1.removeByFileName('far.js');
72
- const secondCount = cer_1._messageDetails.length;
73
- expect(firstCount).toBe(1);
74
- expect(secondCount).toBe(0);
75
- });
76
-
77
- it('check exist error', () => {
78
- const cer_1 = new CompilerErrorResult();
79
- expect(cer_1.checkExistError()).toBe(false);
80
- const cer_2 = new CompilerErrorResult({
81
- code: 1,
82
- message: 'fail',
83
- messageDetails: [{ content: 'error-1', filename: 'far.js' }],
84
- });
85
- expect(cer_2.checkExistError()).toBe(true);
86
- });
87
-
88
- it('get value', () => {
89
- const cer_1 = new CompilerErrorResult();
90
- expect(cer_1.value).toStrictEqual({
91
- code: 1,
92
- message: `Compilation failure 0 files with Babel.`,
93
- messageDetails: [],
94
- });
95
- const cer_2 = new CompilerErrorResult({
96
- code: 1,
97
- message: 'fail',
98
- messageDetails: [{ content: 'error-1', filename: 'far.js' }],
99
- });
100
- expect(cer_2.value).toStrictEqual({
101
- code: 1,
102
- message: `Compilation failure 1 files with Babel.`,
103
- messageDetails: [{ content: 'error-1', filename: 'far.js' }],
104
- });
105
- });
106
-
107
- it('_messageDetails', () => {
108
- const cer_1 = new CompilerErrorResult();
109
- expect(cer_1._messageDetails).toStrictEqual([]);
110
- const cer_2 = new CompilerErrorResult({
111
- code: 1,
112
- message: 'fail',
113
- messageDetails: [{ content: 'error-1', filename: 'far.js' }],
114
- });
115
- expect(cer_2._messageDetails).toStrictEqual([
116
- { content: 'error-1', filename: 'far.js' },
117
- ]);
118
- });
119
- });
@@ -1,12 +0,0 @@
1
- import { defaultDistFileExtMap } from '../src/constants';
2
-
3
- describe('constants', () => {
4
- it('defaultDistFileExtMap', () => {
5
- expect(defaultDistFileExtMap).toStrictEqual({
6
- '.js': '.js',
7
- '.jsx': '.js',
8
- '.ts': '.js',
9
- '.tsx': '.js',
10
- });
11
- });
12
- });
@@ -1,29 +0,0 @@
1
- import { mergeDefaultOption } from '../src/defaults';
2
-
3
- describe('defaults', () => {
4
- it('should merge default option', () => {
5
- const option_1 = mergeDefaultOption({
6
- rootDir: './',
7
- distDir: './dist',
8
- filenames: ['far.js'],
9
- });
10
- expect(option_1).toStrictEqual({
11
- rootDir: './',
12
- distDir: './dist',
13
- filenames: ['far.js'],
14
- enableWatch: false,
15
- enableVirtualDist: false,
16
- extensions: [],
17
- distFileExtMap: {
18
- '.js': '.js',
19
- '.jsx': '.js',
20
- '.ts': '.js',
21
- '.tsx': '.js',
22
- },
23
- ignore: [],
24
- quiet: false,
25
- verbose: false,
26
- clean: false,
27
- });
28
- });
29
- });
@@ -1 +0,0 @@
1
- conts a = 1;
@@ -1 +0,0 @@
1
- conts a = 1;
File without changes
File without changes
@@ -1,2 +0,0 @@
1
- // eslint-disable-next-line
2
- conts a = 1;
File without changes
@@ -1,2 +0,0 @@
1
- const a = 1;
2
- console.info('this is test', a);
File without changes
File without changes
File without changes
File without changes
@@ -1,2 +0,0 @@
1
- const a = 1;
2
- console.info(a);
@@ -1,2 +0,0 @@
1
- const far = 1;
2
- //# sourceMappingURL=far.js.map
@@ -1,108 +0,0 @@
1
- import * as path from 'path';
2
- import { DEFAULT_EXTENSIONS } from '@babel/core';
3
- import {
4
- getFinalCompilerOption,
5
- getFilesFromDir,
6
- getFinalExtensions,
7
- getGlobPattern,
8
- } from '../src/getFinalOption';
9
- import { defaultDistFileExtMap } from '../src/constants';
10
-
11
- const projectDir = path.join(__dirname, './fixtures/getFinalOption');
12
- const sourceDir = path.join(projectDir, 'sourceDir');
13
- const watchDir = path.join(projectDir, 'watchDir');
14
-
15
- describe('get final compilerOption', () => {
16
- it('getGlobPattern', () => {
17
- const pattern_1 = getGlobPattern(sourceDir, ['.js']);
18
- expect(pattern_1).toBe(`${sourceDir}/**/*.js`);
19
- const pattern_2 = getGlobPattern(watchDir, ['.js', '.jsx']);
20
- expect(pattern_2).toBe(`${watchDir}/**/*{.js,.jsx}`);
21
- const pattern_3 = getGlobPattern(watchDir, []);
22
- expect(pattern_3).toBe(`${watchDir}/**/*`);
23
- });
24
-
25
- it('getFinalExtensions', () => {
26
- const finalexts_1 = getFinalExtensions(['.ts', '.tsx']);
27
- expect(finalexts_1).toStrictEqual(['.ts', '.tsx', ...DEFAULT_EXTENSIONS]);
28
- const finalexts_2 = getFinalExtensions(defaultExts => [
29
- '.ts',
30
- '.tsx',
31
- ...defaultExts,
32
- ]);
33
- expect(finalexts_2).toStrictEqual(['.ts', '.tsx', ...DEFAULT_EXTENSIONS]);
34
- const finalexts_3 = getFinalExtensions(() => ['.ts', '.tsx']);
35
- expect(finalexts_3).toStrictEqual(['.ts', '.tsx']);
36
- const finalexts_4 = getFinalExtensions(undefined);
37
- expect(finalexts_4).toStrictEqual(DEFAULT_EXTENSIONS);
38
- });
39
-
40
- it('getFilesFromDir', () => {
41
- const files_1 = getFilesFromDir({ dir: watchDir, finalExt: ['.js'] });
42
- expect(files_1.length).toBe(1);
43
- const files_2 = getFilesFromDir({
44
- dir: watchDir,
45
- finalExt: ['.js', '.jsx'],
46
- });
47
- expect(files_2.length).toBe(2);
48
- const files_3 = getFilesFromDir({
49
- dir: watchDir,
50
- finalExt: ['.js', '.jsx'],
51
- ignore: ['**/far.js'],
52
- });
53
- expect(files_3.length).toBe(1);
54
- const files_4 = getFilesFromDir({ dir: watchDir });
55
- expect(files_4.length).toBe(2);
56
- });
57
-
58
- it('getFinalCompilerOption', () => {
59
- const baseOption = {
60
- rootDir: projectDir,
61
- distDir: path.join(projectDir, 'dist'),
62
- };
63
- const baseFinalOption = {
64
- ...baseOption,
65
- enableWatch: false,
66
- enableVirtualDist: false,
67
- extensions: [],
68
- distFileExtMap: defaultDistFileExtMap,
69
- ignore: [],
70
- quiet: false,
71
- verbose: false,
72
- clean: false,
73
- };
74
- const option_1 = getFinalCompilerOption({ ...baseOption });
75
- expect(option_1).toStrictEqual({
76
- ...baseFinalOption,
77
- filenames: [],
78
- });
79
- const option_2 = getFinalCompilerOption({ ...baseOption, sourceDir });
80
- expect(option_2.filenames.length).toBe(1);
81
- expect(path.normalize(option_2.filenames[0])).toBe(
82
- path.normalize(path.join(sourceDir, './bar.js')),
83
- );
84
- const option_3 = getFinalCompilerOption({ ...baseOption, watchDir });
85
- expect(option_3.filenames.length).toBe(0);
86
- const option_4 = getFinalCompilerOption({
87
- ...baseOption,
88
- enableWatch: true,
89
- watchDir,
90
- });
91
- expect(option_4.filenames.length).toBe(2);
92
- expect(
93
- option_4.filenames.every(filename =>
94
- [
95
- path.normalize(path.join(watchDir, './far.js')),
96
- path.normalize(path.join(watchDir, './foo.jsx')),
97
- ].includes(path.normalize(filename)),
98
- ),
99
- ).toBe(true);
100
-
101
- const option_5 = getFinalCompilerOption({
102
- ...baseOption,
103
- filenames: ['./c.js'],
104
- sourceDir,
105
- });
106
- expect(option_5.filenames.length).toBe(2);
107
- });
108
- });
@@ -1,89 +0,0 @@
1
- import * as path from 'path';
2
- import { logger } from '@modern-js/utils';
3
- import { compiler } from '../src';
4
- import {
5
- sourceDirAndFileNamesValidMessage,
6
- watchDirValidMessage,
7
- } from '../src/validate';
8
-
9
- const projectDir = path.join(__dirname, './fixtures/lib');
10
- const srcDir = path.join(projectDir, 'src');
11
- const distDir = path.join(projectDir, 'dist');
12
-
13
- const originalLogInfo = logger.info;
14
- const originalLogError = logger.error;
15
-
16
- describe('babel compiler', () => {
17
- let testLogs: any[] = [];
18
- const mockedLogInfo = (s: string | number | Error | undefined) =>
19
- testLogs.push(s);
20
- beforeEach(() => {
21
- logger.info = mockedLogInfo;
22
- logger.error = mockedLogInfo;
23
- });
24
-
25
- it('normal compiler', async () => {
26
- const ret = await compiler(
27
- {
28
- rootDir: srcDir,
29
- filenames: [path.join(srcDir, 'index.js')],
30
- distDir,
31
- enableVirtualDist: true,
32
- },
33
- {},
34
- );
35
-
36
- expect(ret.code).toBe(0);
37
- expect(ret.virtualDists?.length).toBe(1);
38
- });
39
-
40
- it('compiler with valid', async () => {
41
- const ret = await compiler(
42
- {
43
- rootDir: srcDir,
44
- distDir,
45
- enableVirtualDist: true,
46
- },
47
- {},
48
- );
49
-
50
- expect(ret.code).toBe(1);
51
- expect(ret.message).toBe(sourceDirAndFileNamesValidMessage);
52
-
53
- const ret_1 = await compiler(
54
- {
55
- rootDir: srcDir,
56
- distDir,
57
- filenames: [path.join(srcDir, 'index.js')],
58
- enableWatch: true,
59
- enableVirtualDist: true,
60
- },
61
- {},
62
- );
63
-
64
- expect((ret_1 as any).code).toBe(1);
65
- expect((ret_1 as any).message).toBe(watchDirValidMessage);
66
- });
67
-
68
- it('compiler in watch mode', async () => {
69
- const emitter = await compiler(
70
- {
71
- rootDir: srcDir,
72
- filenames: [path.join(srcDir, 'index.js')],
73
- distDir,
74
- enableWatch: true,
75
- watchDir: srcDir,
76
- enableVirtualDist: true,
77
- },
78
- {},
79
- );
80
-
81
- expect('on' in emitter).toBe(true);
82
- });
83
-
84
- afterEach(() => {
85
- logger.info = originalLogInfo;
86
- logger.error = originalLogError;
87
- testLogs = [];
88
- });
89
- });
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "@modern-js/tsconfig/base",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "jsx": "preserve",
6
- "baseUrl": "./",
7
- "outDir": "./out",
8
- "emitDeclarationOnly": true,
9
- "isolatedModules": true,
10
- "paths": {},
11
- "types": ["node", "jest"]
12
- }
13
- }
@@ -1,20 +0,0 @@
1
- // import * as path from 'path';
2
- // import { fs } from '@modern-js/utils';
3
- // import { addSourceMappingUrl } from '../src/utils';
4
-
5
- describe('utils test', () => {
6
- it('addSourceMappingUrl should right', () => {
7
- // const code = 'const far = 1;';
8
- // const mapLoc = `far.js.map`;
9
- // const codeWithSourceMappingUrl = addSourceMappingUrl(code, mapLoc);
10
- // const rightCodeWithSourceMappingUrl = fs.readFileSync(
11
- // path.join(__dirname, './fixtures/utils/far'),
12
- // 'utf-8',
13
- // );
14
- // expect(rightCodeWithSourceMappingUrl.trim()).toMatch(
15
- // codeWithSourceMappingUrl.trim(),
16
- // );
17
- // FIXME: git 回车在 Windows 与 Unix 下不一致
18
- expect(0).toBe(0);
19
- });
20
- });
@@ -1,68 +0,0 @@
1
- import {
2
- validate,
3
- validateWatchDir,
4
- validateSourceDirAndFileNames,
5
- sourceDirAndFileNamesValidMessage,
6
- watchDirValidMessage,
7
- } from '../src/validate';
8
-
9
- describe('valide', () => {
10
- const baseOption = { rootDir: './', distDir: './dist', quiet: true };
11
-
12
- it('valide sourceDir and filenams config', () => {
13
- const ret_1 = validateSourceDirAndFileNames({
14
- ...baseOption,
15
- sourceDir: './src',
16
- });
17
- expect(ret_1).toBe(null);
18
- const ret_2 = validateSourceDirAndFileNames({
19
- ...baseOption,
20
- filenames: ['./far.js'],
21
- });
22
- expect(ret_2).toBe(null);
23
-
24
- const ret_3 = validateSourceDirAndFileNames({
25
- ...baseOption,
26
- sourceDir: './src',
27
- filenames: ['./far.js'],
28
- });
29
- expect(ret_3).toBe(null);
30
-
31
- const ret_4 = validateSourceDirAndFileNames({ ...baseOption });
32
- expect(ret_4).toStrictEqual({
33
- code: 1,
34
- message: sourceDirAndFileNamesValidMessage,
35
- virtualDists: [],
36
- });
37
- });
38
-
39
- it('valid watchDir config', () => {
40
- const ret_1 = validateWatchDir({ ...baseOption, enableWatch: true });
41
- expect(ret_1).toStrictEqual({
42
- code: 1,
43
- message: watchDirValidMessage,
44
- virtualDists: [],
45
- });
46
-
47
- const ret_2 = validateWatchDir({
48
- ...baseOption,
49
- enableWatch: true,
50
- watchDir: './src',
51
- });
52
- expect(ret_2).toBe(null);
53
- });
54
-
55
- it('validate', () => {
56
- const ret_1 = validate({ ...baseOption, sourceDir: './src' });
57
- expect(ret_1).toBe(null);
58
- const ret_2 = validate({ ...baseOption, filenames: ['./far.js'] });
59
- expect(ret_2).toBe(null);
60
- const ret_3 = validate({
61
- ...baseOption,
62
- sourceDir: './src',
63
- enableWatch: true,
64
- watchDir: './src',
65
- });
66
- expect(ret_3).toBe(null);
67
- });
68
- });