-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ types | |
.eslintcache | ||
*.log* | ||
*.env* | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { dirname, resolve } from "node:path"; | ||
import { writeFile, mkdir } from "node:fs/promises"; | ||
import { defineBuildConfig } from "unbuild"; | ||
import { build, type BuildOptions, transform } from "esbuild"; | ||
|
||
export default defineBuildConfig({ | ||
hooks: { | ||
async "build:before"(ctx) { | ||
ctx.options.alias["zeptomatch"] = await buildZeptomatch(); | ||
}, | ||
}, | ||
}); | ||
|
||
async function buildZeptomatch() { | ||
let bundle = await build(<BuildOptions>{ | ||
format: "iife", | ||
globalName: "__lib__", | ||
bundle: true, | ||
write: false, | ||
stdin: { | ||
resolveDir: process.cwd(), | ||
contents: /* js */ `export { default as zeptomatch } from "zeptomatch";`, | ||
}, | ||
}).then((r) => r.outputFiles![0].text); | ||
|
||
bundle = (await transform(bundle, { minify: true })).code!; | ||
|
||
bundle = /* js */ ` | ||
let _lazyMatch = () => { ${bundle}; return __lib__.default || __lib__; }; | ||
let _match; | ||
export default (path, pattern) => { | ||
if (!_match) { | ||
_match = _lazyMatch(); | ||
_lazyMatch = null; | ||
} | ||
return _match(path, pattern); | ||
}; | ||
`; | ||
|
||
const outFile = resolve("tmp/node_modules/zeptomatch/zeptomatch.min.mjs"); | ||
await mkdir(dirname(outFile), { recursive: true }); | ||
await writeFile(outFile, bundle); | ||
return outFile; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,13 +49,15 @@ | |
"@types/node": "^22.10.2", | ||
"@vitest/coverage-v8": "^2.1.8", | ||
"changelogen": "^0.5.7", | ||
"esbuild": "^0.24.2", | ||
"eslint": "^9.17.0", | ||
"eslint-config-unjs": "^0.4.2", | ||
"jiti": "^2.4.2", | ||
"prettier": "^3.4.2", | ||
"typescript": "^5.7.2", | ||
"unbuild": "^3.2.0", | ||
"vitest": "^2.1.8" | ||
"vitest": "^2.1.8", | ||
"zeptomatch": "^2.0.0" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters