Skip to content

Commit

Permalink
refactor: changed up the build process and package.json settings to p…
Browse files Browse the repository at this point in the history
…rovide seperate builds for cjs and esm environments
  • Loading branch information
ncpa0cpl committed Aug 3, 2022
1 parent cf262e9 commit 80d10c8
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 48 deletions.
3 changes: 1 addition & 2 deletions jsx-runtime.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from "./dist/jsx/jsx.types";
export * from "./dist/jsx/jsx-runtime";
export * from "./dist/types/jsx-runtime";
3 changes: 1 addition & 2 deletions jsx-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ var __exportStar =
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderToHTML = void 0;
__exportStar(require("./dist/jsx/jsx.types"), exports);
__exportStar(require("./dist/jsx/jsx-runtime"), exports);
__exportStar(require("./dist/legacy/jsx-runtime"), exports);
27 changes: 22 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@
"@types/jest": "^27.5.1",
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"esbuild": "^0.14.51",
"eslint": "^8.15.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint": "^8.15.0",
"git-hook-tasks": "github:ncpa0cpl/git-hook-tasks",
"husky": "^8.0.1",
"jest": "^28.1.0",
"prettier-plugin-jsdoc": "^0.3.38",
"prettier": "^2.6.2",
"prettier-plugin-jsdoc": "^0.3.38",
"ts-jest": "^28.0.2",
"typescript": "^4.6.4"
"typescript": "^4.7.4"
},
"name": "jsxte",
"version": "1.0.0",
"main": "./dist/index.js",
"main": "./dist/legacy/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.cjs"
},
"./jsx-runtime": {
"types": "./dist/types/jsx/jsx-runtime.d.ts",
"import": "./dist/esm/jsx-runtime.mjs",
"require": "./dist/cjs/jsx-runtime.cjs"
}
},
"scripts": {
"build": "rm -rf ./dist && tsc -p tsconfig.build.json",
"build": "rm -rf ./dist && yarn build:esm && yarn build:cjs && yarn build:types",
"build:esm": "node ./scripts/build.mjs esmodule",
"build:cjs": "node ./scripts/build.mjs commonjs",
"build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly --outDir ./dist/types",
"test:lint": "eslint .",
"test:tsc": "tsc --noEmit",
"test:jest": "jest --coverage"
Expand Down
57 changes: 57 additions & 0 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// const esbuild = require("esbuild");
// const path = require("path");
import esbuild from "esbuild";
import path from "path";

// get first process argument
const argv = process.argv.at(2);

if (argv !== "esmodule" && argv !== "commonjs") {
console.error("Invalid target, allowed values: 'esmodule', 'commonjs'");
process.exit(1);
}

const format = argv === "esmodule" ? "esm" : "cjs";
const outDir = format === "esm" ? "./dist/esm" : "./dist/cjs";

const ext = format === "esm" ? ".mjs" : ".cjs";

async function main() {
await esbuild.build({
outfile: path.resolve(process.cwd(), outDir, `index${ext}`),
tsconfig: path.resolve(process.cwd(), "tsconfig.build.json"),
entryPoints: [path.resolve(process.cwd(), "src/index.ts")],
format: format,
bundle: true,
});

await esbuild.build({
outfile: path.resolve(process.cwd(), outDir, `jsx-runtime${ext}`),
tsconfig: path.resolve(process.cwd(), "tsconfig.build.json"),
entryPoints: [path.resolve(process.cwd(), "src/jsx/jsx-runtime.ts")],
format: format,
bundle: true,
});

if (format === "cjs") {
const legacyDir = "./dist/legacy";

await esbuild.build({
outfile: path.resolve(process.cwd(), legacyDir, `index.js`),
tsconfig: path.resolve(process.cwd(), "tsconfig.build.json"),
entryPoints: [path.resolve(process.cwd(), "src/index.ts")],
format: "cjs",
bundle: true,
});

await esbuild.build({
outfile: path.resolve(process.cwd(), legacyDir, `jsx-runtime.js`),
tsconfig: path.resolve(process.cwd(), "tsconfig.build.json"),
entryPoints: [path.resolve(process.cwd(), "src/jsx/jsx-runtime.ts")],
format: "cjs",
bundle: true,
});
}
}

main();
34 changes: 0 additions & 34 deletions scripts/check-build.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export {
type ContextMap,
defineContext,
} from "./context-map/context-map";
export type { HTMLProps, AttributeBool } from "./jsx/base-html-tag-props";
export type { AttributeBool } from "./jsx/base-html-tag-props";
export type { HTMLProps } from "./jsx/base-html-tag-props";
export * from "./jsx/jsx.types";
2 changes: 2 additions & 0 deletions src/jsx-runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./jsx/jsx.types";
export * from "./jsx/jsx-runtime";
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"outDir": "./dist",
"rootDirs": ["./src", "./__tests__"],
Expand Down
134 changes: 130 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,132 @@ error-ex@^1.3.1:
dependencies:
is-arrayish "^0.2.1"

esbuild-android-64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-android-64/-/esbuild-android-64-0.14.51.tgz#414a087cb0de8db1e347ecca6c8320513de433db"
integrity sha512-6FOuKTHnC86dtrKDmdSj2CkcKF8PnqkaIXqvgydqfJmqBazCPdw+relrMlhGjkvVdiiGV70rpdnyFmA65ekBCQ==

esbuild-android-arm64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-android-arm64/-/esbuild-android-arm64-0.14.51.tgz#55de3bce2aab72bcd2b606da4318ad00fb9c8151"
integrity sha512-vBtp//5VVkZWmYYvHsqBRCMMi1MzKuMIn5XDScmnykMTu9+TD9v0NMEDqQxvtFToeYmojdo5UCV2vzMQWJcJ4A==

esbuild-darwin-64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-darwin-64/-/esbuild-darwin-64-0.14.51.tgz#4259f23ed6b4cea2ec8a28d87b7fb9801f093754"
integrity sha512-YFmXPIOvuagDcwCejMRtCDjgPfnDu+bNeh5FU2Ryi68ADDVlWEpbtpAbrtf/lvFTWPexbgyKgzppNgsmLPr8PA==

esbuild-darwin-arm64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.51.tgz#d77b4366a71d84e530ba019d540b538b295d494a"
integrity sha512-juYD0QnSKwAMfzwKdIF6YbueXzS6N7y4GXPDeDkApz/1RzlT42mvX9jgNmyOlWKN7YzQAYbcUEJmZJYQGdf2ow==

esbuild-freebsd-64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.51.tgz#27b6587b3639f10519c65e07219d249b01f2ad38"
integrity sha512-cLEI/aXjb6vo5O2Y8rvVSQ7smgLldwYY5xMxqh/dQGfWO+R1NJOFsiax3IS4Ng300SVp7Gz3czxT6d6qf2cw0g==

esbuild-freebsd-arm64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.51.tgz#63c435917e566808c71fafddc600aca4d78be1ec"
integrity sha512-TcWVw/rCL2F+jUgRkgLa3qltd5gzKjIMGhkVybkjk6PJadYInPtgtUBp1/hG+mxyigaT7ib+od1Xb84b+L+1Mg==

esbuild-linux-32@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-linux-32/-/esbuild-linux-32-0.14.51.tgz#c3da774143a37e7f11559b9369d98f11f997a5d9"
integrity sha512-RFqpyC5ChyWrjx8Xj2K0EC1aN0A37H6OJfmUXIASEqJoHcntuV3j2Efr9RNmUhMfNE6yEj2VpYuDteZLGDMr0w==

esbuild-linux-64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.14.51.tgz#5d92b67f674e02ae0b4a9de9a757ba482115c4ae"
integrity sha512-dxjhrqo5i7Rq6DXwz5v+MEHVs9VNFItJmHBe1CxROWNf4miOGoQhqSG8StStbDkQ1Mtobg6ng+4fwByOhoQoeA==

esbuild-linux-arm64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.51.tgz#dac84740516e859d8b14e1ecc478dd5241b10c93"
integrity sha512-D9rFxGutoqQX3xJPxqd6o+kvYKeIbM0ifW2y0bgKk5HPgQQOo2k9/2Vpto3ybGYaFPCE5qTGtqQta9PoP6ZEzw==

esbuild-linux-arm@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-linux-arm/-/esbuild-linux-arm-0.14.51.tgz#b3ae7000696cd53ed95b2b458554ff543a60e106"
integrity sha512-LsJynDxYF6Neg7ZC7748yweCDD+N8ByCv22/7IAZglIEniEkqdF4HCaa49JNDLw1UQGlYuhOB8ZT/MmcSWzcWg==

esbuild-linux-mips64le@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.51.tgz#dad10770fac94efa092b5a0643821c955a9dd385"
integrity sha512-vS54wQjy4IinLSlb5EIlLoln8buh1yDgliP4CuEHumrPk4PvvP4kTRIG4SzMXm6t19N0rIfT4bNdAxzJLg2k6A==

esbuild-linux-ppc64le@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.51.tgz#b68c2f8294d012a16a88073d67e976edd4850ae0"
integrity sha512-xcdd62Y3VfGoyphNP/aIV9LP+RzFw5M5Z7ja+zdpQHHvokJM7d0rlDRMN+iSSwvUymQkqZO+G/xjb4/75du8BQ==

esbuild-linux-riscv64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.51.tgz#608a318b8697123e44c1e185cdf6708e3df50b93"
integrity sha512-syXHGak9wkAnFz0gMmRBoy44JV0rp4kVCEA36P5MCeZcxFq8+fllBC2t6sKI23w3qd8Vwo9pTADCgjTSf3L3rA==

esbuild-linux-s390x@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.51.tgz#c9e7791170a3295dba79b93aa452beb9838a8625"
integrity sha512-kFAJY3dv+Wq8o28K/C7xkZk/X34rgTwhknSsElIqoEo8armCOjMJ6NsMxm48KaWY2h2RUYGtQmr+RGuUPKBhyw==

esbuild-netbsd-64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.51.tgz#0abd40b8c2e37fda6f5cc41a04cb2b690823d891"
integrity sha512-ZZBI7qrR1FevdPBVHz/1GSk1x5GDL/iy42Zy8+neEm/HA7ma+hH/bwPEjeHXKWUDvM36CZpSL/fn1/y9/Hb+1A==

esbuild-openbsd-64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.51.tgz#4adba0b7ea7eb1428bb00d8e94c199a949b130e8"
integrity sha512-7R1/p39M+LSVQVgDVlcY1KKm6kFKjERSX1lipMG51NPcspJD1tmiZSmmBXoY5jhHIu6JL1QkFDTx94gMYK6vfA==

esbuild-sunos-64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-sunos-64/-/esbuild-sunos-64-0.14.51.tgz#4b8a6d97dfedda30a6e39607393c5c90ebf63891"
integrity sha512-HoHaCswHxLEYN8eBTtyO0bFEWvA3Kdb++hSQ/lLG7TyKF69TeSG0RNoBRAs45x/oCeWaTDntEZlYwAfQlhEtJA==

esbuild-windows-32@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-windows-32/-/esbuild-windows-32-0.14.51.tgz#d31d8ca0c1d314fb1edea163685a423b62e9ac17"
integrity sha512-4rtwSAM35A07CBt1/X8RWieDj3ZUHQqUOaEo5ZBs69rt5WAFjP4aqCIobdqOy4FdhYw1yF8Z0xFBTyc9lgPtEg==

esbuild-windows-64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-windows-64/-/esbuild-windows-64-0.14.51.tgz#7d3c09c8652d222925625637bdc7e6c223e0085d"
integrity sha512-HoN/5HGRXJpWODprGCgKbdMvrC3A2gqvzewu2eECRw2sYxOUoh2TV1tS+G7bHNapPGI79woQJGV6pFH7GH7qnA==

esbuild-windows-arm64@0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.51.tgz#0220d2304bfdc11bc27e19b2aaf56edf183e4ae9"
integrity sha512-JQDqPjuOH7o+BsKMSddMfmVJXrnYZxXDHsoLHc0xgmAZkOOCflRmC43q31pk79F9xuyWY45jDBPolb5ZgGOf9g==

esbuild@^0.14.51:
version "0.14.51"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.14.51.tgz#1c8ecbc8db3710da03776211dc3ee3448f7aa51e"
integrity sha512-+CvnDitD7Q5sT7F+FM65sWkF8wJRf+j9fPcprxYV4j+ohmzVj2W7caUqH2s5kCaCJAfcAICjSlKhDCcvDpU7nw==
optionalDependencies:
esbuild-android-64 "0.14.51"
esbuild-android-arm64 "0.14.51"
esbuild-darwin-64 "0.14.51"
esbuild-darwin-arm64 "0.14.51"
esbuild-freebsd-64 "0.14.51"
esbuild-freebsd-arm64 "0.14.51"
esbuild-linux-32 "0.14.51"
esbuild-linux-64 "0.14.51"
esbuild-linux-arm "0.14.51"
esbuild-linux-arm64 "0.14.51"
esbuild-linux-mips64le "0.14.51"
esbuild-linux-ppc64le "0.14.51"
esbuild-linux-riscv64 "0.14.51"
esbuild-linux-s390x "0.14.51"
esbuild-netbsd-64 "0.14.51"
esbuild-openbsd-64 "0.14.51"
esbuild-sunos-64 "0.14.51"
esbuild-windows-32 "0.14.51"
esbuild-windows-64 "0.14.51"
esbuild-windows-arm64 "0.14.51"

escalade@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"
Expand Down Expand Up @@ -3019,10 +3145,10 @@ type-fest@^0.21.3:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37"
integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==

typescript@^4.6.4:
version "4.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9"
integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==
typescript@^4.7.4:
version "4.7.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==

unist-util-stringify-position@^3.0.0:
version "3.0.2"
Expand Down

0 comments on commit 80d10c8

Please sign in to comment.