Module-Starter ESM Migration

Summary: Ref T2858

Reviewers: #testers, kuba-orlik

Reviewed By: #testers, kuba-orlik

Maniphest Tasks: T2858

Differential Revision: https://hub.sealcode.org/D1662
master
JayNecessary 4 weeks ago
parent d6b4dbca6f
commit 0fc53b26d8

@ -1,7 +1,11 @@
const { build } = require("esbuild");
const glob = require("tiny-glob");
const { promises: fs } = require("node:fs");
const { extname, resolve, relative } = require("node:path");
import * as esbuild from "esbuild";
import { default as glob } from "tiny-glob";
import { promises as fs } from "node:fs";
import { extname, resolve, relative, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const watch = process.argv.at(-1) === "--watch";
@ -40,15 +44,24 @@ const handle_absolute_paths = (project_dir) => ({
let entryPoints = Object.fromEntries(
(await glob("./src/**/*.ts")).map((e) => [e.replace(/\.ts$/, ""), e])
);
build({
const buildOptions = {
entryPoints,
sourcemap: true,
bundle: false,
outdir: "./lib",
logLevel: "info",
platform: "node",
watch,
target: "node16",
target: "es2022",
format: "esm",
plugins: [handle_absolute_paths(__dirname)],
});
};
if (watch) {
const context = await esbuild.context(buildOptions);
await context.watch();
} else {
await esbuild.build(buildOptions);
}
})();

@ -3,8 +3,14 @@
"version": "0.0.1",
"description": "module template",
"main": "lib/src/index.js",
"exports": {
".": {
"types": "./@types/index.d.ts",
"default": "./lib/src/index.js"
}
},
"scripts": {
"build": "node ./esbuild.cjs",
"build": "node ./esbuild.js",
"prepare": "rm -rf @types && npm run typecheck && npm run build-declarations && npm run build",
"pretest": "npm run build",
"test": "node test.cjs",

@ -13,6 +13,7 @@ let mocha_options = [
"--timeout=10000",
"--require",
"source-map-support/register",
"--exit",
];
if (args["test-report"]) {

@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"module": "nodenext",
"moduleResolution": "nodenext",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,

Loading…
Cancel
Save