Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.DS_Store
node_modules
esm
mjs
cjs
types
temp
bun
coverage
Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"assist": {
"actions": {
"source": {
Expand Down
78 changes: 78 additions & 0 deletions cli/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import * as fs from "node:fs/promises";
import { URL } from "node:url";
import ts from "typescript";
import { listFiles, listTsSourceStringLiterals } from "./util.ts";

interface OutputPattern {
destDir: URL;
/** @example .mjs, .cjs */
ext: string;
compilerOptions: ts.CompilerOptions;
}

const outputPattens = new Set<OutputPattern>();
outputPattens.add({
destDir: new URL("../mjs/", import.meta.url),
ext: ".mjs",
compilerOptions: {
target: ts.ScriptTarget.ESNext,
module: ts.ModuleKind.ESNext,
},
});
outputPattens.add({
destDir: new URL("../cjs/", import.meta.url),
ext: ".cjs",
compilerOptions: {
target: ts.ScriptTarget.ESNext,
module: ts.ModuleKind.CommonJS,
},
});

const srcDir = new URL("../src/", import.meta.url);
const exclude = [/\.test\..*$/];
const baseTsConfig = JSON.parse(
await fs.readFile(new URL("../tsconfig.json", import.meta.url), "utf8"),
) as { compilerOptions: ts.CompilerOptions };

for await (const fileUrl of listFiles(srcDir, exclude)) {
const relativePath = fileUrl.pathname.slice(srcDir.pathname.length);
const filePath = fileUrl.pathname.slice(srcDir.pathname.length);
if (filePath.endsWith(".ts")) {
const tsCode = await fs.readFile(fileUrl, "utf-8");
const tsSource = ts.createSourceFile(
filePath,
tsCode,
ts.ScriptTarget.ESNext,
);
const replaceList: Array<ts.StringLiteral> = [];
const ext = ".ts";
for (const node of listTsSourceStringLiterals(tsSource)) {
const importFromText = node.text;
if (importFromText.startsWith(".") && importFromText.endsWith(ext)) {
replaceList.push(node);
}
}
replaceList.sort((n1, n2) => n2.getFullStart() - n1.getFullStart());
for (const pattern of outputPattens) {
let code = tsCode;
for (const node of replaceList) {
const start = code.indexOf(node.text, node.getFullStart());
const end = start + node.text.length;
code = `${code.slice(0, end - ext.length)}${pattern.ext}${code.slice(end)}`;
}
const output = ts.transpileModule(code, {
compilerOptions: {
...baseTsConfig.compilerOptions,
...pattern.compilerOptions,
},
});
const destUrl = new URL(
filePath.replace(/\.ts$/, pattern.ext),
pattern.destDir,
);
await fs.mkdir(new URL(".", destUrl), { recursive: true });
await fs.writeFile(destUrl, output.outputText);
}
console.info(`done:${relativePath}`);
}
}
43 changes: 0 additions & 43 deletions cli/temp.ts

This file was deleted.

96 changes: 48 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
"homepage": "https://github.com/nlibjs/typing",
"repository": "https://github.com/nlibjs/typing",
"type": "module",
"main": "./esm/mod.js",
"exports": {
"import": "./esm/mod.js",
"require": "./cjs/mod.js"
"./package.json": "./package.json",
".": {
"import": "./mjs/mod.js",
"require": "./cjs/mod.js",
"types": "./types/mod.d.ts"
}
},
"files": [
"cjs",
"esm",
"mjs",
"!**/*.test.*"
],
"scripts": {
Expand All @@ -36,20 +39,19 @@
"lint": "biome check",
"build": "run-s build:*",
"build:index": "node cli/generate-index.ts",
"build:temp": "node cli/temp.ts",
"build:esm": "tsc --project tsconfig.esm.json",
"build:cjs": "tsc --project tsconfig.cjs.json",
"build:types": "tsc",
"build:code": "node cli/build.ts",
"version": "run-s version:*",
"version:changelog": "npx @nlib/changelog --output CHANGELOG.md",
"version:add-changelog": "git add CHANGELOG.md",
"version:sync-version": "node cli/sync-version.ts",
"version:add-jsr": "git add jsr.json"
},
"devDependencies": {
"@biomejs/biome": "2.2.4",
"@types/node": "24.5.2",
"@biomejs/biome": "2.2.5",
"@types/node": "24.7.2",
"npm-run-all": "4.1.5",
"typescript": "5.9.2"
"typescript": "5.9.3"
},
"renovate": {
"extends": [
Expand Down
12 changes: 0 additions & 12 deletions tsconfig.cjs.json

This file was deleted.

Loading