Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 3bb97ed

Browse files
committed
Merge branch 'master' into ISSUE-203
2 parents 77c915a + dc0f03d commit 3bb97ed

File tree

21 files changed

+1286
-1725
lines changed

21 files changed

+1286
-1725
lines changed

.github/workflows/integration.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
os: [macos-latest, windows-latest, ubuntu-latest]
11-
node-version: [12.x, 14.x, 16.x]
11+
node-version: [14.x, 16.x, 18.x]
1212

1313
steps:
1414
- uses: actions/checkout@v2
@@ -40,7 +40,7 @@ jobs:
4040
echo "File count do not match source count: ${SOURCE_JS_COUNT} to build ${BUILD_JS_COUNT}"
4141
exit 1
4242
fi
43-
}
43+
}
4444
4545
mkdir -p integration-tests/three.js
4646
git clone --depth 1 https://github.com/mrdoob/three.js.git integration-tests/three.js
@@ -66,20 +66,20 @@ jobs:
6666
EOF
6767
6868
echo "Run swc sync"
69-
rm -rf build
69+
rm -rf build
7070
yarn swc --sync src -d build
7171
checkBuild "src" "build"
7272
73-
rm -rf build-editor
73+
rm -rf build-editor
7474
yarn swc --sync editor -d ./build-editor/
7575
checkBuild "editor" "build-editor"
7676
7777
echo "Run swc async"
78-
rm -rf build
78+
rm -rf build
7979
yarn swc src -d ./build/
8080
checkBuild "src" "build"
8181
82-
rm -rf build-editor
82+
rm -rf build-editor
8383
yarn swc editor -d ./build-editor/
8484
checkBuild "editor" "build-editor"
8585
@@ -108,7 +108,7 @@ jobs:
108108
echo "File count do not match source count: ${SOURCE_JS_COUNT} to build ${BUILD_JS_COUNT}"
109109
exit 1
110110
fi
111-
}
111+
}
112112
113113
mkdir -p integration-tests/rxjs
114114
git clone --depth 1 https://github.com/ReactiveX/rxjs.git integration-tests/rxjs
@@ -142,7 +142,7 @@ jobs:
142142
yarn swc --sync spec -d build-spec
143143
checkBuild "spec" "build-spec"
144144
145-
rm -rf build
145+
rm -rf build
146146
147147
echo "Run swc async"
148148
rm -rf build

.github/workflows/test.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
node-version: [12.x, 14.x, 16.x]
10+
node-version: [14.x, 16.x, 18.x]
1111

1212
steps:
1313
- uses: actions/checkout@v2
@@ -26,6 +26,9 @@ jobs:
2626
- name: Build
2727
run: yarn types
2828

29+
- name: Format
30+
run: yarn prettier --check src examples
31+
2932
- name: Test
3033
run: yarn test
3134

examples/spack-basic/spack.config.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
const { config } = require('@swc/core/spack')
2-
1+
const { config } = require("@swc/core/spack");
32

43
module.exports = config({
5-
entry: {
6-
'web': __dirname + '/src/index.ts',
7-
},
8-
output: {
9-
path: __dirname + '/lib'
10-
},
11-
module: {},
12-
});
4+
entry: {
5+
web: __dirname + "/src/index.ts",
6+
},
7+
output: {
8+
path: __dirname + "/lib",
9+
},
10+
module: {},
11+
});

examples/spack-basic/src/common.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const A = 'foo';
2-
export const B = 'bar';
1+
export const A = "foo";
2+
export const B = "bar";

examples/spack-basic/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { B } from "./common";
22

3-
console.log(B)
3+
console.log(B);
+10-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
const { config } = require('@swc/core/spack')
2-
1+
const { config } = require("@swc/core/spack");
32

43
module.exports = config({
5-
entry: {
6-
'web': __dirname + '/src/web.ts',
7-
'android': __dirname + '/src/android.ts',
8-
},
9-
output: {
10-
path: __dirname + '/lib'
11-
},
12-
module: {},
13-
});
4+
entry: {
5+
web: __dirname + "/src/web.ts",
6+
android: __dirname + "/src/android.ts",
7+
},
8+
output: {
9+
path: __dirname + "/lib",
10+
},
11+
module: {},
12+
});
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import './common';
1+
import "./common";
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('initializing')
1+
console.log("initializing");
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import './common';
1+
import "./common";
+9-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
const { config } = require('@swc/core/spack')
2-
1+
const { config } = require("@swc/core/spack");
32

43
module.exports = config({
5-
entry: {
6-
'web': __dirname + '/src/index.ts',
7-
},
8-
output: {
9-
path: __dirname + '/lib'
10-
},
11-
module: {},
12-
});
4+
entry: {
5+
web: __dirname + "/src/index.ts",
6+
},
7+
output: {
8+
path: __dirname + "/lib",
9+
},
10+
module: {},
11+
});
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { join } from 'path';
1+
import { join } from "path";
22

3-
export const A = join(__dirname, 'src');
3+
export const A = join(__dirname, "src");
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { A } from "./common";
22

3-
console.log(A)
3+
console.log(A);

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@
5757
"@swc/cli": "^0.1.43",
5858
"@swc/core": "^1.2.66",
5959
"@swc/jest": "^0.1.2",
60-
"@types/jest": "^26.0.23",
60+
"@types/jest": "^29.5.0",
6161
"@types/node": "^12.19.16",
6262
"@types/semver": "^7.3.13",
6363
"chokidar": "^3.5.1",
6464
"deepmerge": "^4.2.2",
65-
"jest": "^27.0.3",
65+
"jest": "^29.5.0",
6666
"nano-staged": "^0.4.5",
6767
"prettier": "^2.5.1",
6868
"simple-git-hooks": "^2.7.0",
69-
"ts-jest": "^27.0.4",
69+
"ts-jest": "^29.0.5",
7070
"typescript": "~4.3.2"
7171
},
7272
"peerDependencies": {

src/spack/index.ts

+56-52
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,74 @@
1-
import { bundle } from '@swc/core';
2-
import { mkdir, writeFile } from 'fs';
3-
import { basename, dirname, extname, join, relative } from 'path'
4-
import { promisify } from 'util';
1+
import { bundle } from "@swc/core";
2+
import { mkdir, writeFile } from "fs";
3+
import { basename, dirname, extname, join, relative } from "path";
4+
import { promisify } from "util";
55

6-
import parseSpackArgs from './options';
6+
import parseSpackArgs from "./options";
77

88
const write = promisify(writeFile);
99
const makeDir = promisify(mkdir);
1010

11-
1211
(async () => {
13-
const { spackOptions } = await parseSpackArgs(process.argv);
12+
const { spackOptions } = await parseSpackArgs(process.argv);
1413

15-
function isUserDefinedEntry(name: string) {
16-
if (typeof spackOptions.entry === 'string') {
17-
return spackOptions.entry === name
18-
}
19-
if (Array.isArray(spackOptions.entry)) {
20-
for (const e of spackOptions.entry) {
21-
if (e === name) {
22-
return true;
23-
}
24-
}
25-
return false;
14+
function isUserDefinedEntry(name: string) {
15+
if (typeof spackOptions.entry === "string") {
16+
return spackOptions.entry === name;
17+
}
18+
if (Array.isArray(spackOptions.entry)) {
19+
for (const e of spackOptions.entry) {
20+
if (e === name) {
21+
return true;
2622
}
27-
28-
return name in spackOptions.entry;
23+
}
24+
return false;
2925
}
3026

27+
return name in spackOptions.entry;
28+
}
3129

32-
async function build() {
33-
const bundleStart = process.hrtime();
34-
const output = await bundle(spackOptions);
35-
const bundleEnd = process.hrtime(bundleStart);
36-
console.info(`Bundling done: ${bundleEnd[0]}s ${bundleEnd[1] / 1000000}ms`);
37-
38-
const emitStart = process.hrtime();
39-
if (spackOptions.output?.path) {
40-
await Object.keys(output).map(async (name) => {
41-
let fullPath = '';
42-
if (isUserDefinedEntry(name)) {
43-
fullPath = join(spackOptions.output.path, spackOptions.output.name.replace('[name]', name));
44-
} else {
45-
const ext = extname(name);
46-
const base = basename(name, ext);
47-
const filename = relative(process.cwd(), name);
48-
fullPath = join(spackOptions.output.path, dirname(filename), `${base}.js`)
49-
}
30+
async function build() {
31+
const bundleStart = process.hrtime();
32+
const output = await bundle(spackOptions);
33+
const bundleEnd = process.hrtime(bundleStart);
34+
console.info(`Bundling done: ${bundleEnd[0]}s ${bundleEnd[1] / 1000000}ms`);
5035

51-
await makeDir(dirname(fullPath), { recursive: true });
52-
await write(fullPath, output[name].code, 'utf-8');
53-
if (output[name].map) {
54-
await write(`${fullPath}.map`, output[name].map, 'utf-8')
55-
}
56-
});
36+
const emitStart = process.hrtime();
37+
if (spackOptions.output?.path) {
38+
await Object.keys(output).map(async name => {
39+
let fullPath = "";
40+
if (isUserDefinedEntry(name)) {
41+
fullPath = join(
42+
spackOptions.output.path,
43+
spackOptions.output.name.replace("[name]", name)
44+
);
5745
} else {
58-
throw new Error('Cannot print to stdout: not implemented yet')
46+
const ext = extname(name);
47+
const base = basename(name, ext);
48+
const filename = relative(process.cwd(), name);
49+
fullPath = join(
50+
spackOptions.output.path,
51+
dirname(filename),
52+
`${base}.js`
53+
);
5954
}
60-
const emitEnd = process.hrtime(emitStart);
61-
console.info(`Done: ${emitEnd[0]}s ${emitEnd[1] / 1000000}ms`);
6255

56+
await makeDir(dirname(fullPath), { recursive: true });
57+
await write(fullPath, output[name].code, "utf-8");
58+
if (output[name].map) {
59+
await write(`${fullPath}.map`, output[name].map, "utf-8");
60+
}
61+
});
62+
} else {
63+
throw new Error("Cannot print to stdout: not implemented yet");
6364
}
65+
const emitEnd = process.hrtime(emitStart);
66+
console.info(`Done: ${emitEnd[0]}s ${emitEnd[1] / 1000000}ms`);
67+
}
6468

65-
// if (cliOptions.watch) {
66-
// throw new Error('watch is not implemented yet')
67-
// }
69+
// if (cliOptions.watch) {
70+
// throw new Error('watch is not implemented yet')
71+
// }
6872

69-
await build();
70-
})()
73+
await build();
74+
})();

0 commit comments

Comments
 (0)