Skip to content

Commit

Permalink
Force formatting and fix ci node version requirement (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
3axap4eHko authored Mar 28, 2023
1 parent 2471dae commit dc0f03d
Show file tree
Hide file tree
Showing 21 changed files with 1,287 additions and 1,726 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
node-version: [12.x, 14.x, 16.x]
node-version: [14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
echo "File count do not match source count: ${SOURCE_JS_COUNT} to build ${BUILD_JS_COUNT}"
exit 1
fi
}
}
mkdir -p integration-tests/three.js
git clone --depth 1 https://github.com/mrdoob/three.js.git integration-tests/three.js
Expand All @@ -66,20 +66,20 @@ jobs:
EOF
echo "Run swc sync"
rm -rf build
rm -rf build
yarn swc --sync src -d build
checkBuild "src" "build"
rm -rf build-editor
rm -rf build-editor
yarn swc --sync editor -d ./build-editor/
checkBuild "editor" "build-editor"
echo "Run swc async"
rm -rf build
rm -rf build
yarn swc src -d ./build/
checkBuild "src" "build"
rm -rf build-editor
rm -rf build-editor
yarn swc editor -d ./build-editor/
checkBuild "editor" "build-editor"
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
echo "File count do not match source count: ${SOURCE_JS_COUNT} to build ${BUILD_JS_COUNT}"
exit 1
fi
}
}
mkdir -p integration-tests/rxjs
git clone --depth 1 https://github.com/ReactiveX/rxjs.git integration-tests/rxjs
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
yarn swc --sync spec -d build-spec
checkBuild "spec" "build-spec"
rm -rf build
rm -rf build
echo "Run swc async"
rm -rf build
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -26,6 +26,9 @@ jobs:
- name: Build
run: yarn types

- name: Format
run: yarn prettier --check src examples

- name: Test
run: yarn test

Expand Down
19 changes: 9 additions & 10 deletions examples/spack-basic/spack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const { config } = require('@swc/core/spack')

const { config } = require("@swc/core/spack");

module.exports = config({
entry: {
'web': __dirname + '/src/index.ts',
},
output: {
path: __dirname + '/lib'
},
module: {},
});
entry: {
web: __dirname + "/src/index.ts",
},
output: {
path: __dirname + "/lib",
},
module: {},
});
4 changes: 2 additions & 2 deletions examples/spack-basic/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const A = 'foo';
export const B = 'bar';
export const A = "foo";
export const B = "bar";
2 changes: 1 addition & 1 deletion examples/spack-basic/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { B } from "./common";

console.log(B)
console.log(B);
21 changes: 10 additions & 11 deletions examples/spack-multiple-entry/spack.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const { config } = require('@swc/core/spack')

const { config } = require("@swc/core/spack");

module.exports = config({
entry: {
'web': __dirname + '/src/web.ts',
'android': __dirname + '/src/android.ts',
},
output: {
path: __dirname + '/lib'
},
module: {},
});
entry: {
web: __dirname + "/src/web.ts",
android: __dirname + "/src/android.ts",
},
output: {
path: __dirname + "/lib",
},
module: {},
});
2 changes: 1 addition & 1 deletion examples/spack-multiple-entry/src/android.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import './common';
import "./common";
2 changes: 1 addition & 1 deletion examples/spack-multiple-entry/src/common.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log('initializing')
console.log("initializing");
2 changes: 1 addition & 1 deletion examples/spack-multiple-entry/src/web.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import './common';
import "./common";
19 changes: 9 additions & 10 deletions examples/spack-node-modules/spack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const { config } = require('@swc/core/spack')

const { config } = require("@swc/core/spack");

module.exports = config({
entry: {
'web': __dirname + '/src/index.ts',
},
output: {
path: __dirname + '/lib'
},
module: {},
});
entry: {
web: __dirname + "/src/index.ts",
},
output: {
path: __dirname + "/lib",
},
module: {},
});
4 changes: 2 additions & 2 deletions examples/spack-node-modules/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { join } from 'path';
import { join } from "path";

export const A = join(__dirname, 'src');
export const A = join(__dirname, "src");
2 changes: 1 addition & 1 deletion examples/spack-node-modules/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { A } from "./common";

console.log(A)
console.log(A);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@
"@swc/cli": "^0.1.43",
"@swc/core": "^1.2.66",
"@swc/jest": "^0.1.2",
"@types/jest": "^26.0.23",
"@types/jest": "^29.5.0",
"@types/node": "^12.19.16",
"@types/semver": "^7.3.13",
"chokidar": "^3.5.1",
"deepmerge": "^4.2.2",
"jest": "^27.0.3",
"jest": "^29.5.0",
"nano-staged": "^0.4.5",
"prettier": "^2.5.1",
"simple-git-hooks": "^2.7.0",
"ts-jest": "^27.0.4",
"ts-jest": "^29.0.5",
"typescript": "~4.3.2"
},
"peerDependencies": {
Expand Down
108 changes: 56 additions & 52 deletions src/spack/index.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,74 @@
import { bundle } from '@swc/core';
import { mkdir, writeFile } from 'fs';
import { basename, dirname, extname, join, relative } from 'path'
import { promisify } from 'util';
import { bundle } from "@swc/core";
import { mkdir, writeFile } from "fs";
import { basename, dirname, extname, join, relative } from "path";
import { promisify } from "util";

import parseSpackArgs from './options';
import parseSpackArgs from "./options";

const write = promisify(writeFile);
const makeDir = promisify(mkdir);


(async () => {
const { spackOptions } = await parseSpackArgs(process.argv);
const { spackOptions } = await parseSpackArgs(process.argv);

function isUserDefinedEntry(name: string) {
if (typeof spackOptions.entry === 'string') {
return spackOptions.entry === name
}
if (Array.isArray(spackOptions.entry)) {
for (const e of spackOptions.entry) {
if (e === name) {
return true;
}
}
return false;
function isUserDefinedEntry(name: string) {
if (typeof spackOptions.entry === "string") {
return spackOptions.entry === name;
}
if (Array.isArray(spackOptions.entry)) {
for (const e of spackOptions.entry) {
if (e === name) {
return true;
}

return name in spackOptions.entry;
}
return false;
}

return name in spackOptions.entry;
}

async function build() {
const bundleStart = process.hrtime();
const output = await bundle(spackOptions);
const bundleEnd = process.hrtime(bundleStart);
console.info(`Bundling done: ${bundleEnd[0]}s ${bundleEnd[1] / 1000000}ms`);

const emitStart = process.hrtime();
if (spackOptions.output?.path) {
await Object.keys(output).map(async (name) => {
let fullPath = '';
if (isUserDefinedEntry(name)) {
fullPath = join(spackOptions.output.path, spackOptions.output.name.replace('[name]', name));
} else {
const ext = extname(name);
const base = basename(name, ext);
const filename = relative(process.cwd(), name);
fullPath = join(spackOptions.output.path, dirname(filename), `${base}.js`)
}
async function build() {
const bundleStart = process.hrtime();
const output = await bundle(spackOptions);
const bundleEnd = process.hrtime(bundleStart);
console.info(`Bundling done: ${bundleEnd[0]}s ${bundleEnd[1] / 1000000}ms`);

await makeDir(dirname(fullPath), { recursive: true });
await write(fullPath, output[name].code, 'utf-8');
if (output[name].map) {
await write(`${fullPath}.map`, output[name].map, 'utf-8')
}
});
const emitStart = process.hrtime();
if (spackOptions.output?.path) {
await Object.keys(output).map(async name => {
let fullPath = "";
if (isUserDefinedEntry(name)) {
fullPath = join(
spackOptions.output.path,
spackOptions.output.name.replace("[name]", name)
);
} else {
throw new Error('Cannot print to stdout: not implemented yet')
const ext = extname(name);
const base = basename(name, ext);
const filename = relative(process.cwd(), name);
fullPath = join(
spackOptions.output.path,
dirname(filename),
`${base}.js`
);
}
const emitEnd = process.hrtime(emitStart);
console.info(`Done: ${emitEnd[0]}s ${emitEnd[1] / 1000000}ms`);

await makeDir(dirname(fullPath), { recursive: true });
await write(fullPath, output[name].code, "utf-8");
if (output[name].map) {
await write(`${fullPath}.map`, output[name].map, "utf-8");
}
});
} else {
throw new Error("Cannot print to stdout: not implemented yet");
}
const emitEnd = process.hrtime(emitStart);
console.info(`Done: ${emitEnd[0]}s ${emitEnd[1] / 1000000}ms`);
}

// if (cliOptions.watch) {
// throw new Error('watch is not implemented yet')
// }
// if (cliOptions.watch) {
// throw new Error('watch is not implemented yet')
// }

await build();
})()
await build();
})();
Loading

0 comments on commit dc0f03d

Please sign in to comment.