Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Improve makejs experience #16013

Merged
merged 1 commit into from Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -108,7 +108,10 @@
"yarn": ">=1.4.0"
},
"lint-staged": {
"*.{js,cjs,mjs,ts}": [
"./Makefile.source.mjs": [
"node ./scripts/pack-script.js --auto"
],
"*.{js,cjs,mjs,ts,cts,mts}": [
"eslint --format=codeframe --cache --cache-strategy=content"
]
},
Expand Down
16 changes: 14 additions & 2 deletions scripts/pack-script.js
@@ -1,11 +1,12 @@
import path from "path";
import { writeFileSync } from "fs";
import { readFileSync, writeFileSync } from "fs";
import { rollup } from "rollup";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import { babel } from "@rollup/plugin-babel";
import terser from "@rollup/plugin-terser";
import { commonJS } from "$repo-utils";
import { createHash } from "crypto";

const { __dirname, require } = commonJS(import.meta.url);

Expand All @@ -17,6 +18,16 @@ async function pack(inputPath, outputPath, dynamicRequireTargets) {
inputPath = path.join(__dirname, inputPath);
outputPath = path.join(__dirname, outputPath);

const hash = createHash("sha1")
.update(readFileSync(inputPath, "utf8"))
.digest("hex");

if (process.argv[2] == "--auto") {
if (readFileSync(outputPath, "utf8").includes(hash)) {
return;
}
}

const bundle = await rollup({
input: inputPath,

Expand Down Expand Up @@ -48,7 +59,8 @@ async function pack(inputPath, outputPath, dynamicRequireTargets) {
format: "cjs",
});

const output = `/* eslint-disable */
const output = `// source hash: ${hash}
/* eslint-disable */
// prettier-ignore
${result.output[0].code}`;
writeFileSync(outputPath, output);
Expand Down