Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 2e3a3b9

Browse files
committed
feat: init
0 parents  commit 2e3a3b9

File tree

41 files changed

+4767
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4767
-0
lines changed

.github/workflows/test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Test
2+
on:
3+
push:
4+
branches: [develop]
5+
pull_request:
6+
branches: [master, develop, next]
7+
jobs:
8+
test:
9+
name: Test
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, windows-latest]
14+
timeout-minutes: 10
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
- name: Use Node.js
19+
uses: actions/setup-node@v2
20+
with:
21+
node-version-file: '.nvmrc'
22+
- name: Install dependencies
23+
run: npx ci
24+
- name: Test
25+
run: npm run test
26+
- name: Lint
27+
if: ${{ matrix.os == 'ubuntu-latest' }}
28+
run: npm run lint

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# macOS
2+
.DS_Store
3+
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
12+
# Dependency directories
13+
/node_modules/
14+
15+
# Output of 'npm pack'
16+
*.tgz
17+
18+
# dotenv environment variables file
19+
.env
20+
.env.test
21+
22+
# VSCode
23+
.vscode
24+
25+
# Distribution
26+
dist
27+
28+
# Link config
29+
link.config.json

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v16.14.2

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# cjs-loader
2+
3+
Node.js `require()` hook to transform ESM & TypeScript to CommonJS on demand using [esbuild](https://esbuild.github.io/).
4+
5+
6+
### Features
7+
- Converts ESM & TypeScript to CommonJS
8+
- Supports new extensions `.cjs` + `.mjs` (and `.cts` &`.mts`)
9+
- Supports Node.js 12.16.2 and up
10+
- Handles `node:` import prefixes
11+
- Sourcemap support
12+
- Cached for performance boost
13+
14+
> **Tip:**
15+
>
16+
> _cjs-loader_ doesn't hook into dynamic `import()` calls.
17+
>
18+
> Use this with [esm-loader](https://github.com/esbuild-kit/esm-loader) for `import()` support. Alternatively, use [esb](https://github.com/esbuild-kit/esb) to handle them both automatically.
19+
20+
## Install
21+
22+
```sh
23+
npm install --save-dev @esbuild-kit/cjs-loader
24+
```
25+
26+
## Usage
27+
28+
Pass `@esbuild/cjs-loader` into the [`--require`](https://nodejs.org/api/cli.html#-r---require-module) flag
29+
```sh
30+
node -r @esbuild/cjs-loader ./file.js
31+
```
32+
33+
### TypeScript configuration
34+
The following properties are used from `tsconfig.json` in the working directory:
35+
- `jsxFactory`
36+
- `jsxFragmentFactory`
37+
38+
### Cache
39+
Modules transformations are cached in the system cache directory ([`TMPDIR`](https://en.wikipedia.org/wiki/TMPDIR)). Transforms are cached by content hash so duplicate dependencies are not re-transformed.
40+
41+
Set environment variable `ESBK_DISABLE_CACHE` to a truthy value to disable the cache:
42+
43+
```sh
44+
ESBK_DISABLE_CACHE=1 node -r @esbuild/cjs-loader ./file.js
45+
```
46+
47+
## Related
48+
49+
- [@esbuild-kit/esb](https://github.com/esbuild-kit/esb) - Node.js runtime powered by esbuild using `@esbuild-kit/cjs-loader` and `@esbuild-kit/esb-loader`.
50+
51+
- [@esbuild-kit/esm-loader](https://github.com/esbuild-kit/esm-loader) - TypeScript to ESM transpiler using the Node.js loader API.

package.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "@esbuild-kit/cjs-loader",
3+
"version": "0.0.0-semantic-release",
4+
"description": "Node.js loader for compiling ESM & TypeScript modules to CommonJS",
5+
"keywords": [
6+
"esbuild",
7+
"loader",
8+
"node",
9+
"cjs",
10+
"commonjs",
11+
"esm",
12+
"typescript"
13+
],
14+
"license": "MIT",
15+
"repository": "esbuild-kit/cjs-loader",
16+
"author": {
17+
"name": "Hiroki Osame",
18+
"email": "[email protected]"
19+
},
20+
"files": [
21+
"dist"
22+
],
23+
"main": "./dist/index.js",
24+
"exports": "./dist/index.js",
25+
"scripts": {
26+
"build": "pkgroll --target node12.20 --minify",
27+
"lint": "eslint .",
28+
"pretest": "npm run build",
29+
"test": "node --require ./dist/index.js tests/index.ts"
30+
},
31+
"dependencies": {
32+
"@esbuild-kit/core-utils": "github:esbuild-kit/core-utils#built/develop",
33+
"get-tsconfig": "^3.0.1"
34+
},
35+
"devDependencies": {
36+
"@pvtnbr/eslint-config": "^0.21.0",
37+
"@types/node": "^17.0.31",
38+
"@types/semver": "^7.3.9",
39+
"eslint": "^8.15.0",
40+
"execa": "^6.1.0",
41+
"get-node": "^12.1.0",
42+
"manten": "^0.0.3",
43+
"pkgroll": "^1.2.2",
44+
"semver": "^7.3.7",
45+
"typescript": "^4.6.4"
46+
},
47+
"eslintConfig": {
48+
"extends": "@pvtnbr",
49+
"ignorePatterns": [
50+
"tests/fixtures"
51+
],
52+
"rules": {
53+
"import/no-unresolved": "off",
54+
"@typescript-eslint/no-shadow": [
55+
"error",
56+
{
57+
"allow": [
58+
"describe"
59+
]
60+
}
61+
]
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)