Skip to content

Commit

Permalink
chore: update compilation template
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Sep 17, 2024
1 parent b7708aa commit 7fea7fa
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 56 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 20 additions & 25 deletions tools/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {findPackages, MonoRepo} from "@tsed/monorepo-utils";
import {dirname, join, relative} from "node:path";
import cloneDeep from "lodash/cloneDeep.js";
import omit from "lodash/omit.js";
import get from "lodash/get.js";
import fs from "fs-extra";
import globby from "globby";

Expand All @@ -18,7 +19,6 @@ async function main() {

const tsConfigRootPath = join(monoRepo.rootDir, "tsconfig.json");
const tsConfigTemplate = await fs.readJson(join(scriptDir, "./tsconfig.template.json"));
const tsConfigTemplateCjsPath = join(scriptDir, "./tsconfig.template.cjs.json");
const tsConfigTemplateEsmPath = join(scriptDir, "./tsconfig.template.esm.json");
const tsConfigTemplateSpecPath = join(scriptDir, "./tsconfig.template.spec.json");
const tsConfigTemplateSpec = await fs.readJson(tsConfigTemplateSpecPath);
Expand All @@ -44,7 +44,6 @@ async function main() {
const tsConfig = cloneDeep(tsConfigTemplate);
const tsConfigPath = join(path, "tsconfig.json");
const tsConfigBuildEsmPath = join(path, "tsconfig.esm.json");
const tsConfigBuildCjsPath = join(path, "tsconfig.cjs.json");
const tsConfigBuildSpecPath = join(path, "tsconfig.spec.json");
const npmignore = join(path, ".npmignore");
const vitestPath = join(path, "vitest.config.mts");
Expand Down Expand Up @@ -73,14 +72,9 @@ async function main() {
});
});

tsConfig.references.push(
{
path: "./tsconfig.cjs.json"
},
{
path: "./tsconfig.esm.json"
}
);
tsConfig.references.push({
path: "./tsconfig.esm.json"
});

if (hasFiles.length) {
tsConfig.references.push({
Expand Down Expand Up @@ -121,7 +115,6 @@ async function main() {

await fs.writeJson(tsConfigPath, tsConfig, {spaces: 2});
await fs.copy(tsConfigTemplateEsmPath, tsConfigBuildEsmPath);
await fs.copy(tsConfigTemplateCjsPath, tsConfigBuildCjsPath);
await fs.copy(npmIgnoreTemplatePath, npmignore);

tsConfigRoot.references.push({
Expand Down Expand Up @@ -173,22 +166,24 @@ async function main() {

// pkg.pkg.main = pkg.pkg.main.replace("cjs/", "esm/");

if (pkg.pkg.exports && !pkg.pkg.exports["."]) {
pkg.pkg.exports = {
".": {
...pkg.pkg.exports
}
};
}
pkg.pkg.type = "module";
pkg.pkg.source = "./src/index.ts";
pkg.pkg.main = "./lib/esm/index.js";
pkg.pkg.module = "./lib/esm/index.js";
pkg.pkg.typings = "./lib/types/index.d.ts";
pkg.pkg.exports = {
".": {
...omit(get(pkg, 'pkg.exports["."]', {}), ["require"])
// typings: "./lib/types/index.d.ts",
// default: "./lib/esm/index.js",
// import: "./lib/esm/index.js"
}
};

await fs.writeJson(pkg.path, pkg.pkg, {spaces: 2});
// try {
// fs.removeSync(join(path, "tsconfig.compile.esm.json"));
// fs.removeSync(join(path, "tsconfig.compile.json"));
// fs.removeSync(join(path, "tsconfig.cjs.json"));
// // fs.removeSync(join(path, "tsconfig.esm.json"));
// } catch {
// }
try {
fs.removeSync(join(path, "tsconfig.cjs.json"));
} catch {}
}
}

Expand Down
4 changes: 2 additions & 2 deletions tools/typescript/swc.node.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sourceMaps": "inline",
"jsc": {
"target": "es2021",
"target": "es2023",
"externalHelpers": true,
"keepClassNames": true,
"parser": {
Expand All @@ -23,7 +23,7 @@
}
},
"module": {
"type": "commonjs",
"type": "es6",
"strict": false,
"strictMode": true,
"lazy": false,
Expand Down
28 changes: 0 additions & 28 deletions tools/typescript/tsconfig.template.cjs.json

This file was deleted.

2 changes: 1 addition & 1 deletion tools/typescript/tsconfig.template.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"moduleResolution": "nodenext",
"rootDir": "src",
"outDir": "./lib/esm",
"declarationDir": "./lib/types-esm",
"declarationDir": "./lib/types",
"declaration": true,
"composite": true,
"noEmit": false
Expand Down

0 comments on commit 7fea7fa

Please sign in to comment.