@modern-js/babel-compiler 1.2.2 → 1.2.5
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.
- package/CHANGELOG.md +35 -0
- package/dist/js/modern/buildWatch.js +6 -5
- package/dist/js/modern/compilerErrorResult.js +4 -1
- package/dist/js/modern/getFinalOption.js +1 -1
- package/dist/js/modern/type.js +0 -1
- package/dist/js/node/buildWatch.js +6 -5
- package/dist/js/node/compilerErrorResult.js +4 -1
- package/dist/js/node/getFinalOption.js +2 -6
- package/dist/js/node/type.js +0 -5
- package/dist/types/buildWatch.d.ts +1 -1
- package/dist/types/getFinalOption.d.ts +2 -2
- package/dist/types/type.d.ts +5 -5
- package/package.json +28 -8
- package/jest.config.js +0 -8
- package/modern.config.js +0 -6
- package/tests/.eslintrc.js +0 -6
- package/tests/build.test.ts +0 -122
- package/tests/buildWatch.test.ts +0 -251
- package/tests/compiler.test.ts +0 -112
- package/tests/compilerErrorResult.test.ts +0 -119
- package/tests/constants.test.ts +0 -12
- package/tests/defaults.test.ts +0 -29
- package/tests/fixtures/build/src/error +0 -1
- package/tests/fixtures/build/src/error1 +0 -1
- package/tests/fixtures/build/src/far.js +0 -0
- package/tests/fixtures/build/src/index.js +0 -0
- package/tests/fixtures/buildWatch/src/error +0 -2
- package/tests/fixtures/buildWatch/src/index.js +0 -0
- package/tests/fixtures/compiler/src/index.js +0 -2
- package/tests/fixtures/getFinalOption/sourceDir/bar.js +0 -0
- package/tests/fixtures/getFinalOption/watchDir/far.js +0 -0
- package/tests/fixtures/getFinalOption/watchDir/foo.jsx +0 -0
- package/tests/fixtures/lib/src/index.js +0 -0
- package/tests/fixtures/resolveSourceMap/src/index.js +0 -2
- package/tests/fixtures/utils/far +0 -2
- package/tests/getFinalOption.test.ts +0 -108
- package/tests/index.test.ts +0 -89
- package/tests/tsconfig.json +0 -13
- package/tests/utils.test.ts +0 -20
- package/tests/validate.test.ts +0 -68
- package/tsconfig.json +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @modern-js/babel-compiler
|
|
2
2
|
|
|
3
|
+
## 1.2.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d32f35134: chore: add modern/jest/eslint/ts config files to .npmignore
|
|
8
|
+
- Updated dependencies [d32f35134]
|
|
9
|
+
- Updated dependencies [6ae4a34ae]
|
|
10
|
+
- Updated dependencies [b80229c79]
|
|
11
|
+
- Updated dependencies [948cc4436]
|
|
12
|
+
- @modern-js/utils@1.7.3
|
|
13
|
+
|
|
14
|
+
## 1.2.4
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 0e0537005: fix: unlock @babel/core version
|
|
19
|
+
- 69a728375: fix: remove exports.jsnext:source after publish
|
|
20
|
+
- Updated dependencies [cd7346b0d]
|
|
21
|
+
- Updated dependencies [69a728375]
|
|
22
|
+
- @modern-js/utils@1.7.2
|
|
23
|
+
|
|
24
|
+
## 1.2.3
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- 6cffe99d: chore:
|
|
29
|
+
remove react eslint rules for `modern-js` rule set.
|
|
30
|
+
add .eslintrc for each package to speed up linting
|
|
31
|
+
- 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
|
|
32
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
|
33
|
+
- Updated dependencies [b8599d09]
|
|
34
|
+
- Updated dependencies [60f7d8bf]
|
|
35
|
+
- Updated dependencies [3bf4f8b0]
|
|
36
|
+
- @modern-js/utils@1.5.0
|
|
37
|
+
|
|
3
38
|
## 1.2.2
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
|
@@ -17,7 +17,8 @@ export const BuildWatchEvent = {
|
|
|
17
17
|
export class BuildWatchEmitter extends Event.EventEmitter {
|
|
18
18
|
constructor(...args) {
|
|
19
19
|
super(...args);
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
_defineProperty(this, "_initFn", void 0);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
setInitFn(fn) {
|
|
@@ -42,16 +43,16 @@ export const runBuildWatch = async (option, babelConfig = {}, emitter) => {
|
|
|
42
43
|
quiet
|
|
43
44
|
} = option; // 第一次正常构建
|
|
44
45
|
|
|
45
|
-
const
|
|
46
|
+
const firstBuildResult = await build(option, babelConfig);
|
|
46
47
|
const {
|
|
47
48
|
code
|
|
48
|
-
} =
|
|
49
|
+
} = firstBuildResult;
|
|
49
50
|
|
|
50
51
|
if (code === 1) {
|
|
51
|
-
errorResult.init(
|
|
52
|
+
errorResult.init(firstBuildResult);
|
|
52
53
|
emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
|
|
53
54
|
} else {
|
|
54
|
-
emitter.emit(BuildWatchEvent.firstCompiler,
|
|
55
|
+
emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
return watch(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
|
|
1
3
|
export class CompilerErrorResult {
|
|
2
4
|
constructor(initErrorResult) {
|
|
3
|
-
this
|
|
5
|
+
_defineProperty(this, "_messageDetails", void 0);
|
|
6
|
+
|
|
4
7
|
this.init(initErrorResult);
|
|
5
8
|
}
|
|
6
9
|
|
|
@@ -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
|
|
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) => {
|
package/dist/js/modern/type.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -35,7 +35,8 @@ exports.BuildWatchEvent = BuildWatchEvent;
|
|
|
35
35
|
class BuildWatchEmitter extends Event.EventEmitter {
|
|
36
36
|
constructor(...args) {
|
|
37
37
|
super(...args);
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
_defineProperty(this, "_initFn", void 0);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
setInitFn(fn) {
|
|
@@ -63,16 +64,16 @@ const runBuildWatch = async (option, babelConfig = {}, emitter) => {
|
|
|
63
64
|
quiet
|
|
64
65
|
} = option; // 第一次正常构建
|
|
65
66
|
|
|
66
|
-
const
|
|
67
|
+
const firstBuildResult = await (0, _build.build)(option, babelConfig);
|
|
67
68
|
const {
|
|
68
69
|
code
|
|
69
|
-
} =
|
|
70
|
+
} = firstBuildResult;
|
|
70
71
|
|
|
71
72
|
if (code === 1) {
|
|
72
|
-
errorResult.init(
|
|
73
|
+
errorResult.init(firstBuildResult);
|
|
73
74
|
emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
|
|
74
75
|
} else {
|
|
75
|
-
emitter.emit(BuildWatchEvent.firstCompiler,
|
|
76
|
+
emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
return (0, _utils.watch)(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({
|
|
@@ -5,9 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.CompilerErrorResult = void 0;
|
|
7
7
|
|
|
8
|
+
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; }
|
|
9
|
+
|
|
8
10
|
class CompilerErrorResult {
|
|
9
11
|
constructor(initErrorResult) {
|
|
10
|
-
this
|
|
12
|
+
_defineProperty(this, "_messageDetails", void 0);
|
|
13
|
+
|
|
11
14
|
this.init(initErrorResult);
|
|
12
15
|
}
|
|
13
16
|
|
|
@@ -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
|
|
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;
|
package/dist/js/node/type.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as Event from 'events';
|
|
3
|
-
import { FSWatcher } from '
|
|
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
|
|
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?:
|
|
12
|
+
ignore?: GlobOptions['ignore'];
|
|
13
13
|
}) => string[];
|
|
14
14
|
export declare const getFinalCompilerOption: (option: ICompilerOptions) => IFinaleCompilerOptions;
|
package/dist/types/type.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TransformOptions } from '@babel/core';
|
|
2
|
-
import type {
|
|
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?:
|
|
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:
|
|
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?:
|
|
39
|
+
ignore?: GlobOptions['ignore'];
|
|
40
40
|
enableVirtualDist?: boolean;
|
|
41
41
|
distDir: string;
|
|
42
42
|
watchDir?: string;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.2.
|
|
14
|
+
"version": "1.2.5",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -28,18 +28,16 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@babel/core": "7.
|
|
31
|
+
"@babel/core": "^7.17.0",
|
|
32
32
|
"@babel/runtime": "^7",
|
|
33
|
-
"@modern-js/utils": "^1.
|
|
34
|
-
"chokidar": "^3.5.2",
|
|
35
|
-
"glob": "^7.1.6"
|
|
33
|
+
"@modern-js/utils": "^1.7.3"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
36
|
"@babel/plugin-transform-classes": "^7.14.9",
|
|
39
37
|
"@babel/preset-typescript": "^7",
|
|
40
38
|
"@types/babel__core": "^7.1.15",
|
|
41
39
|
"@types/glob": "^7.1.4",
|
|
42
|
-
"@types/jest": "^
|
|
40
|
+
"@types/jest": "^27",
|
|
43
41
|
"@types/node": "^14",
|
|
44
42
|
"typescript": "^4",
|
|
45
43
|
"@scripts/build": "0.0.0",
|
|
@@ -56,10 +54,32 @@
|
|
|
56
54
|
"registry": "https://registry.npmjs.org/",
|
|
57
55
|
"access": "public"
|
|
58
56
|
},
|
|
57
|
+
"wireit": {
|
|
58
|
+
"build": {
|
|
59
|
+
"command": "modern build",
|
|
60
|
+
"files": [
|
|
61
|
+
"src/**/*",
|
|
62
|
+
"tsconfig.json",
|
|
63
|
+
"package.json"
|
|
64
|
+
],
|
|
65
|
+
"output": [
|
|
66
|
+
"dist/**/*"
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
"test": {
|
|
70
|
+
"command": "jest --passWithNoTests",
|
|
71
|
+
"files": [
|
|
72
|
+
"src/**/*",
|
|
73
|
+
"tsconfig.json",
|
|
74
|
+
"package.json"
|
|
75
|
+
],
|
|
76
|
+
"output": []
|
|
77
|
+
}
|
|
78
|
+
},
|
|
59
79
|
"scripts": {
|
|
60
80
|
"new": "modern new",
|
|
61
|
-
"build": "
|
|
62
|
-
"test": "
|
|
81
|
+
"build": "wireit",
|
|
82
|
+
"test": "wireit"
|
|
63
83
|
},
|
|
64
84
|
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
65
85
|
}
|
package/jest.config.js
DELETED
package/modern.config.js
DELETED
package/tests/.eslintrc.js
DELETED
package/tests/build.test.ts
DELETED
|
@@ -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
|
-
});
|