tshy 1.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +39 -0
- package/.github/workflows/typedoc.yml +50 -0
- package/LICENSE.md +63 -0
- package/README.md +235 -0
- package/dist/esm/bins.d.ts +3 -0
- package/dist/esm/bins.d.ts.map +1 -0
- package/dist/esm/bins.js +18 -0
- package/dist/esm/bins.js.map +1 -0
- package/dist/esm/build.d.ts +2 -0
- package/dist/esm/build.d.ts.map +1 -0
- package/dist/esm/build.js +56 -0
- package/dist/esm/build.js.map +1 -0
- package/dist/esm/config.d.ts +4 -0
- package/dist/esm/config.d.ts.map +1 -0
- package/dist/esm/config.js +85 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/dialects.d.ts +3 -0
- package/dist/esm/dialects.d.ts.map +1 -0
- package/dist/esm/dialects.js +3 -0
- package/dist/esm/dialects.js.map +1 -0
- package/dist/esm/exports.d.ts +4 -0
- package/dist/esm/exports.d.ts.map +1 -0
- package/dist/esm/exports.js +89 -0
- package/dist/esm/exports.js.map +1 -0
- package/dist/esm/fail.d.ts +2 -0
- package/dist/esm/fail.d.ts.map +1 -0
- package/dist/esm/fail.js +7 -0
- package/dist/esm/fail.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.d.ts +4 -0
- package/dist/esm/package.d.ts.map +1 -0
- package/dist/esm/package.js +16 -0
- package/dist/esm/package.js.map +1 -0
- package/dist/esm/polyfills.d.ts +3 -0
- package/dist/esm/polyfills.d.ts.map +1 -0
- package/dist/esm/polyfills.js +13 -0
- package/dist/esm/polyfills.js.map +1 -0
- package/dist/esm/set-folder-dialect.d.ts +4 -0
- package/dist/esm/set-folder-dialect.d.ts.map +1 -0
- package/dist/esm/set-folder-dialect.js +9 -0
- package/dist/esm/set-folder-dialect.js.map +1 -0
- package/dist/esm/sources.d.ts +3 -0
- package/dist/esm/sources.d.ts.map +1 -0
- package/dist/esm/sources.js +19 -0
- package/dist/esm/sources.js.map +1 -0
- package/dist/esm/tsconfig.d.ts +2 -0
- package/dist/esm/tsconfig.d.ts.map +1 -0
- package/dist/esm/tsconfig.js +55 -0
- package/dist/esm/tsconfig.js.map +1 -0
- package/dist/esm/types.d.ts +38 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/write-package.d.ts +3 -0
- package/dist/esm/write-package.d.ts.map +1 -0
- package/dist/esm/write-package.js +6 -0
- package/dist/esm/write-package.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +92 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1383 -0
- package/docs/functions/bins.default.html +60 -0
- package/docs/functions/fail.fail.html +67 -0
- package/docs/functions/set_folder_dialect.default.html +67 -0
- package/docs/functions/write_package.default.html +60 -0
- package/docs/index.html +172 -0
- package/docs/modules/bins.html +61 -0
- package/docs/modules/build.html +54 -0
- package/docs/modules/config.html +61 -0
- package/docs/modules/dialects.html +61 -0
- package/docs/modules/exports.html +61 -0
- package/docs/modules/fail.html +61 -0
- package/docs/modules/index.html +54 -0
- package/docs/modules/package.html +61 -0
- package/docs/modules/polyfills.html +61 -0
- package/docs/modules/set_folder_dialect.html +61 -0
- package/docs/modules/sources.html +61 -0
- package/docs/modules/tsconfig.html +54 -0
- package/docs/modules/types.html +65 -0
- package/docs/modules/write_package.html +61 -0
- package/docs/types/types.Dialect.html +56 -0
- package/docs/types/types.Export.html +72 -0
- package/docs/types/types.Package.html +73 -0
- package/docs/types/types.TshyConfig.html +63 -0
- package/docs/types/types.TshyExport.html +56 -0
- package/docs/variables/config.default.html +56 -0
- package/docs/variables/dialects.default.html +56 -0
- package/docs/variables/exports.default.html +56 -0
- package/docs/variables/package.default.html +56 -0
- package/docs/variables/polyfills.default.html +56 -0
- package/docs/variables/sources.default.html +56 -0
- package/package.json +71 -0
- package/scripts/fixup.sh +5 -0
- package/src/bins.ts +15 -0
- package/src/build.ts +64 -0
- package/src/config.ts +117 -0
- package/src/dialects.ts +2 -0
- package/src/exports.ts +105 -0
- package/src/fail.ts +5 -0
- package/src/index.ts +17 -0
- package/src/package.ts +18 -0
- package/src/polyfills.ts +21 -0
- package/src/set-folder-dialect.ts +16 -0
- package/src/sources.ts +20 -0
- package/src/tsconfig.ts +65 -0
- package/src/types.ts +43 -0
- package/src/write-package.ts +6 -0
- package/tsconfig/esm.json +7 -0
- package/tsconfig.json +17 -0
- package/typedoc.json +7 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
strategy:
|
|
8
|
+
matrix:
|
|
9
|
+
node-version: [16.x, 18.x, 19.x]
|
|
10
|
+
platform:
|
|
11
|
+
- os: ubuntu-latest
|
|
12
|
+
shell: bash
|
|
13
|
+
- os: macos-latest
|
|
14
|
+
shell: bash
|
|
15
|
+
- os: windows-latest
|
|
16
|
+
shell: bash
|
|
17
|
+
- os: windows-latest
|
|
18
|
+
shell: powershell
|
|
19
|
+
fail-fast: false
|
|
20
|
+
|
|
21
|
+
runs-on: ${{ matrix.platform.os }}
|
|
22
|
+
defaults:
|
|
23
|
+
run:
|
|
24
|
+
shell: ${{ matrix.platform.shell }}
|
|
25
|
+
|
|
26
|
+
steps:
|
|
27
|
+
- name: Checkout Repository
|
|
28
|
+
uses: actions/checkout@v1.1.0
|
|
29
|
+
|
|
30
|
+
- name: Use Nodejs ${{ matrix.node-version }}
|
|
31
|
+
uses: actions/setup-node@v1
|
|
32
|
+
with:
|
|
33
|
+
node-version: ${{ matrix.node-version }}
|
|
34
|
+
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: npm install
|
|
37
|
+
|
|
38
|
+
- name: Run Tests
|
|
39
|
+
run: npm test -- -c -t0
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Simple workflow for deploying static content to GitHub Pages
|
|
2
|
+
name: Deploy static content to Pages
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
# Runs on pushes targeting the default branch
|
|
6
|
+
push:
|
|
7
|
+
branches: ["main"]
|
|
8
|
+
|
|
9
|
+
# Allows you to run this workflow manually from the Actions tab
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
pages: write
|
|
16
|
+
id-token: write
|
|
17
|
+
|
|
18
|
+
# Allow one concurrent deployment
|
|
19
|
+
concurrency:
|
|
20
|
+
group: "pages"
|
|
21
|
+
cancel-in-progress: true
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
# Single deploy job since we're just deploying
|
|
25
|
+
deploy:
|
|
26
|
+
environment:
|
|
27
|
+
name: github-pages
|
|
28
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
steps:
|
|
31
|
+
- name: Checkout
|
|
32
|
+
uses: actions/checkout@v3
|
|
33
|
+
- name: Use Nodejs ${{ matrix.node-version }}
|
|
34
|
+
uses: actions/setup-node@v3
|
|
35
|
+
with:
|
|
36
|
+
node-version: 18.x
|
|
37
|
+
- name: Install dependencies
|
|
38
|
+
run: npm install
|
|
39
|
+
- name: Generate typedocs
|
|
40
|
+
run: npm run typedoc
|
|
41
|
+
|
|
42
|
+
- name: Setup Pages
|
|
43
|
+
uses: actions/configure-pages@v3
|
|
44
|
+
- name: Upload artifact
|
|
45
|
+
uses: actions/upload-pages-artifact@v1
|
|
46
|
+
with:
|
|
47
|
+
path: './docs'
|
|
48
|
+
- name: Deploy to GitHub Pages
|
|
49
|
+
id: deployment
|
|
50
|
+
uses: actions/deploy-pages@v1
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
All packages under `src/` are licensed according to the terms in
|
|
2
|
+
their respective `LICENSE` or `LICENSE.md` files.
|
|
3
|
+
|
|
4
|
+
The remainder of this project is licensed under the Blue Oak
|
|
5
|
+
Model License, as follows:
|
|
6
|
+
|
|
7
|
+
-----
|
|
8
|
+
|
|
9
|
+
# Blue Oak Model License
|
|
10
|
+
|
|
11
|
+
Version 1.0.0
|
|
12
|
+
|
|
13
|
+
## Purpose
|
|
14
|
+
|
|
15
|
+
This license gives everyone as much permission to work with
|
|
16
|
+
this software as possible, while protecting contributors
|
|
17
|
+
from liability.
|
|
18
|
+
|
|
19
|
+
## Acceptance
|
|
20
|
+
|
|
21
|
+
In order to receive this license, you must agree to its
|
|
22
|
+
rules. The rules of this license are both obligations
|
|
23
|
+
under that agreement and conditions to your license.
|
|
24
|
+
You must not do anything with this software that triggers
|
|
25
|
+
a rule that you cannot or will not follow.
|
|
26
|
+
|
|
27
|
+
## Copyright
|
|
28
|
+
|
|
29
|
+
Each contributor licenses you to do everything with this
|
|
30
|
+
software that would otherwise infringe that contributor's
|
|
31
|
+
copyright in it.
|
|
32
|
+
|
|
33
|
+
## Notices
|
|
34
|
+
|
|
35
|
+
You must ensure that everyone who gets a copy of
|
|
36
|
+
any part of this software from you, with or without
|
|
37
|
+
changes, also gets the text of this license or a link to
|
|
38
|
+
<https://blueoakcouncil.org/license/1.0.0>.
|
|
39
|
+
|
|
40
|
+
## Excuse
|
|
41
|
+
|
|
42
|
+
If anyone notifies you in writing that you have not
|
|
43
|
+
complied with [Notices](#notices), you can keep your
|
|
44
|
+
license by taking all practical steps to comply within 30
|
|
45
|
+
days after the notice. If you do not do so, your license
|
|
46
|
+
ends immediately.
|
|
47
|
+
|
|
48
|
+
## Patent
|
|
49
|
+
|
|
50
|
+
Each contributor licenses you to do everything with this
|
|
51
|
+
software that would otherwise infringe any patent claims
|
|
52
|
+
they can license or become able to license.
|
|
53
|
+
|
|
54
|
+
## Reliability
|
|
55
|
+
|
|
56
|
+
No contributor can revoke this license.
|
|
57
|
+
|
|
58
|
+
## No Liability
|
|
59
|
+
|
|
60
|
+
***As far as the law allows, this software comes as is,
|
|
61
|
+
without any warranty or condition, and no contributor
|
|
62
|
+
will be liable to anyone for any damages related to this
|
|
63
|
+
software or this license, under any kind of legal claim.***
|
package/README.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# tshy - TypeScript HYbridizer
|
|
2
|
+
|
|
3
|
+
Hybrid (CommonJS/ESM) TypeScript node package builder.
|
|
4
|
+
|
|
5
|
+
This tool manages the `exports` in your package.json file, and
|
|
6
|
+
builds your TypeScript program using `tsc` 5.2 in both ESM and
|
|
7
|
+
CJS modes.
|
|
8
|
+
|
|
9
|
+
## USAGE
|
|
10
|
+
|
|
11
|
+
Install tshy:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm i -D tshy
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Put this in your package.json to use it with the default configs:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"prepare": "tshy"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Put your source code in `./src`.
|
|
31
|
+
|
|
32
|
+
The built files will end up in `./dist/esm` (ESM) and
|
|
33
|
+
`./dist/commonjs` (CommonJS).
|
|
34
|
+
|
|
35
|
+
Your `exports` will be edited to reflect the correct module entry
|
|
36
|
+
points.
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
Mostly, this is opinionated convention, and so there is very
|
|
41
|
+
little to configure.
|
|
42
|
+
|
|
43
|
+
Source must be in `./src`. Builds are in `./dist/cjs` for
|
|
44
|
+
CommonJS and `./dist/mjs` for ESM.
|
|
45
|
+
|
|
46
|
+
There is very little configuration for this. The only thing to
|
|
47
|
+
decide is the exported paths. If you have a `./index.ts` file,
|
|
48
|
+
then that will be listed as the main `"."` export by default.
|
|
49
|
+
|
|
50
|
+
You can set other entry points by putting this in your
|
|
51
|
+
`package.json` file:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"tshy": {
|
|
56
|
+
"exports": {
|
|
57
|
+
"./foo": "./src/foo.ts",
|
|
58
|
+
"./bar": "./src/bar.ts",
|
|
59
|
+
".": "./src/something-other-than-index.ts",
|
|
60
|
+
"./package.json": "./package.json"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Any exports pointing to files in `./src` will be updated to their
|
|
67
|
+
appropriate build target locations, like:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"exports": {
|
|
72
|
+
"./foo": {
|
|
73
|
+
"import": {
|
|
74
|
+
"types": "./dist/mjs/foo.d.ts",
|
|
75
|
+
"default": "./dist/mjs/foo.js"
|
|
76
|
+
},
|
|
77
|
+
"require": {
|
|
78
|
+
"types": "./dist/cjs/foo.d.ts",
|
|
79
|
+
"default": "./dist/cjs/foo.js"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Any exports that are not within `./src` will not be built, and
|
|
87
|
+
can be either a string, or a `{ import, require, types }` object:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"exports": {
|
|
92
|
+
"./package.json": "./package.json"
|
|
93
|
+
"./thing": {
|
|
94
|
+
"import": "./lib/thing.mjs",
|
|
95
|
+
"require": "./lib/thing.cjs",
|
|
96
|
+
"types": "./lib/thing.d.ts"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Selecting Dialects
|
|
103
|
+
|
|
104
|
+
You can tell tshy which dialect you're building for by setting
|
|
105
|
+
the `dialects` config to an array of strings:
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"tshy": {
|
|
110
|
+
"dialects": [
|
|
111
|
+
"esm",
|
|
112
|
+
"commonjs"
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The default is `["esm", "commonjs"]` (ie, both of them). If you
|
|
119
|
+
set it to just one, then only that dialect will be built and
|
|
120
|
+
exported.
|
|
121
|
+
|
|
122
|
+
## CommonJS Dialect Polyfills
|
|
123
|
+
|
|
124
|
+
Sometimes you have to do something in different ways depending on
|
|
125
|
+
the JS dialect in use. For example, maybe you have to use
|
|
126
|
+
`import.meta.url` in ESM, but polyfill with
|
|
127
|
+
`pathToFileURL(__filename)` in CommonJS.
|
|
128
|
+
|
|
129
|
+
To do this, create a polyfill file with the CommonJS code in
|
|
130
|
+
`<name>-cjs.cts`. (The `cts` extension matters.)
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
// src/source-dir-cjs.cts
|
|
134
|
+
// ^^^^^^^^^^--------- matching name
|
|
135
|
+
// ^^^^----- "-cts" tag
|
|
136
|
+
// ^^^^- ".cts" filename suffix
|
|
137
|
+
// this one has a -cjs.cts suffix, so it will override the
|
|
138
|
+
// module at src/source-dir.ts in the CJS build,
|
|
139
|
+
// and be excluded from the esm build.
|
|
140
|
+
import { pathToFileURL } from 'node:url'
|
|
141
|
+
//@ts-ignore - Have to ignore because TSC thinks this is ESM
|
|
142
|
+
export const sourceDir = pathToFileURL(__dirname)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Then put the "real" ESM code in `<name>.ts` (not `.mts`!)
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
// src/source-dir.ts
|
|
149
|
+
// This is the ESM version of the module
|
|
150
|
+
export const sourceDir = new URL('.', import.meta.url)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Then in your code, you can just `import { sourceDir } from
|
|
154
|
+
'./source-dir.js'` and it'll work in both dialects.
|
|
155
|
+
|
|
156
|
+
## `.cts` and `.mts` files
|
|
157
|
+
|
|
158
|
+
Files named `*.mts` will be excluded from the CommonJS build.
|
|
159
|
+
|
|
160
|
+
Files named `*.cts` will be excluded from the ESM build.
|
|
161
|
+
|
|
162
|
+
If you need to do something one way for CJS and another way for
|
|
163
|
+
ESM, use the "Dialect Switching" trick, with the ESM code living
|
|
164
|
+
in `src/<whatever>.ts` and the CommonJS polyfill living in
|
|
165
|
+
`src/<whatever>-cjs.cts`.
|
|
166
|
+
|
|
167
|
+
## Atomic Builds
|
|
168
|
+
|
|
169
|
+
Code is built in `./.tshy-build-tmp` and then copied over only if
|
|
170
|
+
the build succeeds. This makes it work in monorepo cases where
|
|
171
|
+
you may have packages that depend on one another and are all
|
|
172
|
+
being built in parallel (as long as they've been built one time,
|
|
173
|
+
of course).
|
|
174
|
+
|
|
175
|
+
## Exports Management
|
|
176
|
+
|
|
177
|
+
The `exports` field in your package.json file will be updated
|
|
178
|
+
based on the `tshy.exports` configuration, as described above.
|
|
179
|
+
|
|
180
|
+
If you don't provide that config, then the default is:
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
{
|
|
184
|
+
"tshy": {
|
|
185
|
+
"exports": {
|
|
186
|
+
".": "./src/index.ts",
|
|
187
|
+
"./package.json": "./package.json"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Package `#imports`
|
|
194
|
+
|
|
195
|
+
Using the `imports` field in `package.json` is not currently
|
|
196
|
+
supported, because this looks at the nearest `package.json` to
|
|
197
|
+
get local imports, and the package.json files placed in
|
|
198
|
+
`dist/{cjs,mjs}` can't have local imports outside of their
|
|
199
|
+
folders.
|
|
200
|
+
|
|
201
|
+
There's a way it could theoretically be done, but it's a bit
|
|
202
|
+
complicated. A future version may support this.
|
|
203
|
+
|
|
204
|
+
## TSConfigs
|
|
205
|
+
|
|
206
|
+
Put whatever configuration you want in `tsconfig.json`, with the
|
|
207
|
+
following caveats:
|
|
208
|
+
|
|
209
|
+
* `include` - will be overridden based on build, best omitted
|
|
210
|
+
* `exclude` - will be overridden based on build, best omitted
|
|
211
|
+
* compilerOptions:
|
|
212
|
+
* `outDir` - will be overridden based on build, best omitted
|
|
213
|
+
* `rootDir` - will be set to `./src` in the build, can only
|
|
214
|
+
cause annoying errors otherwise.
|
|
215
|
+
* `target` - will be set to `es2022`
|
|
216
|
+
* `module` - will be set to `NodeNext`
|
|
217
|
+
* `moduleResolution` - will be set to `NodeNext`
|
|
218
|
+
|
|
219
|
+
If you don't have a `tsconfig.json` file, then one will be
|
|
220
|
+
provided for you.
|
|
221
|
+
|
|
222
|
+
Then the `tsconfig.json` file will be used as the default project
|
|
223
|
+
for code hints in VSCode/nvim, your tests, etc.
|
|
224
|
+
|
|
225
|
+
## `src/package.json`
|
|
226
|
+
|
|
227
|
+
As of TypeScript 5.2, the only way to emit JavaScript to ESM or
|
|
228
|
+
CJS, and also import packages using node-style `"exports"`-aware
|
|
229
|
+
module resolution, is to set the `type` field in the
|
|
230
|
+
`package.json` file closest to the TypeScript source code.
|
|
231
|
+
|
|
232
|
+
During the build, `tshy` will create a file at `src/package.json`
|
|
233
|
+
for this purpose, and then delete it afterwards. If that file
|
|
234
|
+
exists and _wasn't_ put there by `tshy`, then it will be
|
|
235
|
+
destroyed.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bins.d.ts","sourceRoot":"","sources":["../../src/bins.ts"],"names":[],"mappings":";AAIA,wBAUC"}
|
package/dist/esm/bins.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// chmod bins after build
|
|
2
|
+
import { chmodSync } from 'fs';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import pkg from './package.js';
|
|
5
|
+
export default () => {
|
|
6
|
+
const { bin } = pkg;
|
|
7
|
+
if (!bin)
|
|
8
|
+
return;
|
|
9
|
+
if (typeof bin === 'string') {
|
|
10
|
+
chmodSync(resolve(bin), 0o755);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
for (const v of Object.values(bin)) {
|
|
14
|
+
chmodSync(resolve(v), 0o755);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=bins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bins.js","sourceRoot":"","sources":["../../src/bins.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,GAAG,MAAM,cAAc,CAAA;AAC9B,eAAe,GAAG,EAAE;IAClB,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IACnB,IAAI,CAAC,GAAG;QAAE,OAAM;IAChB,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;KAC/B;SAAM;QACL,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YAClC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;SAC7B;KACF;AACH,CAAC,CAAA","sourcesContent":["// chmod bins after build\nimport { chmodSync } from 'fs'\nimport { resolve } from 'path'\nimport pkg from './package.js'\nexport default () => {\n const { bin } = pkg\n if (!bin) return\n if (typeof bin === 'string') {\n chmodSync(resolve(bin), 0o755)\n } else {\n for (const v of Object.values(bin)) {\n chmodSync(resolve(v), 0o755)\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAWA,OAAO,eAAe,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { renameSync } from 'node:fs';
|
|
4
|
+
import { relative, resolve } from 'node:path/posix';
|
|
5
|
+
import { rimrafSync } from 'rimraf';
|
|
6
|
+
import { syncContentSync } from 'sync-content';
|
|
7
|
+
import bins from './bins.js';
|
|
8
|
+
import dialects from './dialects.js';
|
|
9
|
+
import { fail } from './fail.js';
|
|
10
|
+
import polyfills from './polyfills.js';
|
|
11
|
+
import setFolderDialect from './set-folder-dialect.js';
|
|
12
|
+
import './tsconfig.js';
|
|
13
|
+
import writePackage from './write-package.js';
|
|
14
|
+
const buildFail = (res) => {
|
|
15
|
+
setFolderDialect('src');
|
|
16
|
+
fail('build failed');
|
|
17
|
+
console.error(res);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
};
|
|
20
|
+
rimrafSync('.tshy-build-tmp');
|
|
21
|
+
if (dialects.includes('esm')) {
|
|
22
|
+
setFolderDialect('src', 'esm');
|
|
23
|
+
const res = spawnSync('tsc -p .tshy/esm.json', {
|
|
24
|
+
shell: true,
|
|
25
|
+
stdio: 'inherit',
|
|
26
|
+
});
|
|
27
|
+
setFolderDialect('src');
|
|
28
|
+
if (res.status || res.signal)
|
|
29
|
+
buildFail(res);
|
|
30
|
+
setFolderDialect('.tshy-build-tmp/esm', 'esm');
|
|
31
|
+
console.error(chalk.cyan.bold('built esm'));
|
|
32
|
+
}
|
|
33
|
+
if (dialects.includes('commonjs')) {
|
|
34
|
+
setFolderDialect('src', 'commonjs');
|
|
35
|
+
const res = spawnSync('tsc -p .tshy/commonjs.json', {
|
|
36
|
+
shell: true,
|
|
37
|
+
stdio: 'inherit',
|
|
38
|
+
});
|
|
39
|
+
setFolderDialect('src');
|
|
40
|
+
if (res.status || res.signal)
|
|
41
|
+
buildFail(res);
|
|
42
|
+
setFolderDialect('.tshy-build-tmp/commonjs', 'commonjs');
|
|
43
|
+
console.error(chalk.cyan.bold('built commonjs'), res);
|
|
44
|
+
// apply polyfills
|
|
45
|
+
for (const [f, t] of polyfills.entries()) {
|
|
46
|
+
const stemFrom = resolve('.tshy-build-tmp/commonjs', relative(resolve('src'), resolve(f))).replace(/\.cts$/, '');
|
|
47
|
+
const stemTo = resolve('.tshy-build-tmp/commonjs', relative(resolve('src'), resolve(t))).replace(/\.ts$/, '');
|
|
48
|
+
renameSync(`${stemFrom}.cjs`, `${stemTo}.js`);
|
|
49
|
+
renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
syncContentSync('.tshy-build-tmp', 'dist');
|
|
53
|
+
rimrafSync('.tshy-build-tmp');
|
|
54
|
+
bins();
|
|
55
|
+
writePackage();
|
|
56
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAoB,MAAM,oBAAoB,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,QAAQ,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,gBAAgB,MAAM,yBAAyB,CAAA;AACtD,OAAO,eAAe,CAAA;A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AAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,CAAC,CAAA;IACrD,kBAAkB;IAClB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE;QACxC,MAAM,QAAQ,GAAG,OAAO,CACtB,0BAA0B,EAC1B,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CACrC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;QACvB,MAAM,MAAM,GAAG,OAAO,CACpB,0BAA0B,EAC1B,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CACrC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;QACtB,UAAU,CAAC,GAAG,QAAQ,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,CAAA;QAC7C,UAAU,CAAC,GAAG,QAAQ,QAAQ,EAAE,GAAG,MAAM,OAAO,CAAC,CAAA;KAClD;CACF;AAED,eAAe,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAA;AAC1C,UAAU,CAAC,iBAAiB,CAAC,CAAA;AAC7B,IAAI,EAAE,CAAA;AACN,YAAY,EAAE,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { spawnSync, SpawnSyncReturns } from 'node:child_process'\nimport { renameSync } from 'node:fs'\nimport { relative, resolve } from 'node:path/posix'\nimport { rimrafSync } from 'rimraf'\nimport { syncContentSync } from 'sync-content'\nimport bins from './bins.js'\nimport dialects from './dialects.js'\nimport { fail } from './fail.js'\nimport polyfills from './polyfills.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport './tsconfig.js'\nimport writePackage from './write-package.js'\n\nconst buildFail = (res: SpawnSyncReturns<Buffer>) => {\n setFolderDialect('src')\n fail('build failed')\n console.error(res)\n process.exit(1)\n}\n\nrimrafSync('.tshy-build-tmp')\n\nif (dialects.includes('esm')) {\n setFolderDialect('src', 'esm')\n const res = spawnSync('tsc -p .tshy/esm.json', {\n shell: true,\n stdio: 'inherit',\n })\n setFolderDialect('src')\n if (res.status || res.signal) buildFail(res)\n setFolderDialect('.tshy-build-tmp/esm', 'esm')\n console.error(chalk.cyan.bold('built esm'))\n}\n\nif (dialects.includes('commonjs')) {\n setFolderDialect('src', 'commonjs')\n const res = spawnSync('tsc -p .tshy/commonjs.json', {\n shell: true,\n stdio: 'inherit',\n })\n setFolderDialect('src')\n if (res.status || res.signal) buildFail(res)\n setFolderDialect('.tshy-build-tmp/commonjs', 'commonjs')\n console.error(chalk.cyan.bold('built commonjs'), res)\n // apply polyfills\n for (const [f, t] of polyfills.entries()) {\n const stemFrom = resolve(\n '.tshy-build-tmp/commonjs',\n relative(resolve('src'), resolve(f))\n ).replace(/\\.cts$/, '')\n const stemTo = resolve(\n '.tshy-build-tmp/commonjs',\n relative(resolve('src'), resolve(t))\n ).replace(/\\.ts$/, '')\n renameSync(`${stemFrom}.cjs`, `${stemTo}.js`)\n renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`)\n }\n}\n\nsyncContentSync('.tshy-build-tmp', 'dist')\nrimrafSync('.tshy-build-tmp')\nbins()\nwritePackage()\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,UAAU,EAAc,MAAM,YAAY,CAAA;AAgHrE,QAAA,MAAM,MAAM,EAAE,UAAoC,CAAA;AAClD,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// get the config and package and stuff
|
|
2
|
+
import { fail } from './fail.js';
|
|
3
|
+
const validConfig = (e) => !!e &&
|
|
4
|
+
typeof e === 'object' &&
|
|
5
|
+
(e.exports === undefined || validExports(e['exports'])) &&
|
|
6
|
+
(e.dialects === undefined || validDialects(e['dialects']));
|
|
7
|
+
const isDialect = (d) => d === 'commonjs' || d === 'esm';
|
|
8
|
+
const validDialects = (d) => !!d && Array.isArray(d) && !d.some(d => !isDialect(d));
|
|
9
|
+
const validExports = (e) => {
|
|
10
|
+
if (!e)
|
|
11
|
+
return false;
|
|
12
|
+
if (typeof e !== 'object')
|
|
13
|
+
return false;
|
|
14
|
+
for (const [sub, exp] of Object.entries(e)) {
|
|
15
|
+
if (sub !== '.' && !sub.startsWith('./')) {
|
|
16
|
+
fail(`tshy.exports key must be "." or start with "./", got: ${sub}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
if (typeof exp === 'string') {
|
|
20
|
+
e[sub] = addDot(exp);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (typeof exp !== 'object' || !exp || Array.isArray(exp)) {
|
|
24
|
+
fail(`tshy.exports ${sub} value must be string or import/require object, ` +
|
|
25
|
+
`got: ${JSON.stringify(exp)}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
const { import: i, require: r } = exp;
|
|
29
|
+
if (!i && !e) {
|
|
30
|
+
fail(`tshy.exports ${sub} needs require or import, ` +
|
|
31
|
+
`got: ${JSON.stringify(exp)}`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
if ((i !== undefined && typeof i !== 'string') ||
|
|
35
|
+
(r !== undefined && typeof r !== 'string')) {
|
|
36
|
+
fail(`tshy.exports ${sub} import/require must be strings, ` +
|
|
37
|
+
`got: ${JSON.stringify(exp)}`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
if ((i !== undefined && join(i).startsWith('src/')) ||
|
|
41
|
+
(r !== undefined && join(r).startsWith('src/'))) {
|
|
42
|
+
fail(`tshy.exports ${sub} in src/ must be string paths, ` +
|
|
43
|
+
`got: ${JSON.stringify(exp)}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
e[sub] = {};
|
|
47
|
+
if (e[sub].types)
|
|
48
|
+
e[sub].types = addDot(e[sub].types);
|
|
49
|
+
if (e[sub].import)
|
|
50
|
+
e[sub].types = addDot(e[sub].import);
|
|
51
|
+
if (e[sub].require)
|
|
52
|
+
e[sub].types = addDot(e[sub].require);
|
|
53
|
+
}
|
|
54
|
+
if (e.dialects) {
|
|
55
|
+
if (!validDialects(e.dialects)) {
|
|
56
|
+
fail(`tshy.dialects must be array containing 'esm' and/or 'commonjs', ` +
|
|
57
|
+
`got: ${JSON.stringify(e.dialects)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
};
|
|
62
|
+
const addDot = (s) => `./${join(s)}`;
|
|
63
|
+
const getConfig = (pkg, sources) => {
|
|
64
|
+
const tshy = validConfig(pkg.tshy) ? pkg.tshy : {};
|
|
65
|
+
if (tshy.exports)
|
|
66
|
+
return tshy;
|
|
67
|
+
const e = {
|
|
68
|
+
'./package.json': './package.json',
|
|
69
|
+
};
|
|
70
|
+
for (const i of sources) {
|
|
71
|
+
if (/^\.\/src\/index\.[^\.]+$/.test(i)) {
|
|
72
|
+
e['.'] = i;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
pkg.tshy = tshy;
|
|
77
|
+
tshy.exports = e;
|
|
78
|
+
return tshy;
|
|
79
|
+
};
|
|
80
|
+
import { join } from 'path/posix';
|
|
81
|
+
import pkg from './package.js';
|
|
82
|
+
import sources from './sources.js';
|
|
83
|
+
const config = getConfig(pkg, sources);
|
|
84
|
+
export default config;
|
|
85
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,MAAM,WAAW,GAAG,CAAC,CAAM,EAAmB,EAAE,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C,CAAA;YACV,MAAK;SACN;KACF;IACD,GAAG,CAAC,IAAI,GAAG,IAAI,CAAA;IACf,IAAI,CAAC,OAAO,GAAG,CAAC,CAAA;IAChB,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,GAAG,MAAM,cAAc,CAAA;AAC9B,OAAO,OAAO,MAAM,cAAc,CAAA;AAElC,MAAM,MAAM,GAAe,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAClD,eAAe,MAAM,CAAA","sourcesContent":["// get the config and package and stuff\n\nimport { fail } from './fail.js'\nimport { Dialect, Package, TshyConfig, TshyExport } from './types.js'\n\nconst validConfig = (e: any): e is TshyConfig =>\n !!e &&\n typeof e === 'object' &&\n (e.exports === undefined || validExports(e['exports'])) &&\n (e.dialects === undefined || validDialects(e['dialects']))\n\nconst isDialect = (d: any): d is Dialect =>\n d === 'commonjs' || d === 'esm'\n\nconst validDialects = (\n d: any\n): d is Exclude<TshyConfig['dialects'], undefined> =>\n !!d && Array.isArray(d) && !d.some(d => !isDialect(d))\n\nconst validExports = (\n e: any\n): e is Exclude<TshyConfig['exports'], undefined> => {\n if (!e) return false\n if (typeof e !== 'object') return false\n for (const [sub, exp] of Object.entries(e)) {\n if (sub !== '.' && !sub.startsWith('./')) {\n fail(\n `tshy.exports key must be \".\" or start with \"./\", got: ${sub}`\n )\n process.exit(1)\n }\n if (typeof exp === 'string') {\n e[sub] = addDot(exp)\n continue\n }\n if (typeof exp !== 'object' || !exp || Array.isArray(exp)) {\n fail(\n `tshy.exports ${sub} value must be string or import/require object, ` +\n `got: ${JSON.stringify(exp)}`\n )\n process.exit(1)\n }\n const { import: i, require: r } = exp as Exclude<\n TshyExport,\n string\n >\n if (!i && !e) {\n fail(\n `tshy.exports ${sub} needs require or import, ` +\n `got: ${JSON.stringify(exp)}`\n )\n process.exit(1)\n }\n if (\n (i !== undefined && typeof i !== 'string') ||\n (r !== undefined && typeof r !== 'string')\n ) {\n fail(\n `tshy.exports ${sub} import/require must be strings, ` +\n `got: ${JSON.stringify(exp)}`\n )\n process.exit(1)\n }\n if (\n (i !== undefined && join(i).startsWith('src/')) ||\n (r !== undefined && join(r).startsWith('src/'))\n ) {\n fail(\n `tshy.exports ${sub} in src/ must be string paths, ` +\n `got: ${JSON.stringify(exp)}`\n )\n process.exit(1)\n }\n e[sub] = {}\n if (e[sub].types) e[sub].types = addDot(e[sub].types)\n if (e[sub].import) e[sub].types = addDot(e[sub].import)\n if (e[sub].require) e[sub].types = addDot(e[sub].require)\n }\n if (e.dialects) {\n if (!validDialects(e.dialects)) {\n fail(\n `tshy.dialects must be array containing 'esm' and/or 'commonjs', ` +\n `got: ${JSON.stringify(e.dialects)}`\n )\n }\n }\n return true\n}\n\nconst addDot = (s: string) => `./${join(s)}`\n\nconst getConfig = (\n pkg: Package,\n sources: Set<string>\n): TshyConfig => {\n const tshy: TshyConfig = validConfig(pkg.tshy) ? pkg.tshy : {}\n if (tshy.exports) return tshy\n const e: Exclude<TshyConfig['exports'], undefined> = {\n './package.json': './package.json',\n }\n for (const i of sources) {\n if (/^\\.\\/src\\/index\\.[^\\.]+$/.test(i)) {\n e['.'] = i\n break\n }\n }\n pkg.tshy = tshy\n tshy.exports = e\n return tshy\n}\n\nimport { join } from 'path/posix'\nimport pkg from './package.js'\nimport sources from './sources.js'\n\nconst config: TshyConfig = getConfig(pkg, sources)\nexport default config\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialects.d.ts","sourceRoot":"","sources":["../../src/dialects.ts"],"names":[],"mappings":";AACA,wBAAqD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialects.js","sourceRoot":"","sources":["../../src/dialects.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,eAAe,MAAM,CAAC,QAAQ,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA","sourcesContent":["import config from './config.js'\nexport default config.dialects || ['esm', 'commonjs']\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAA0B,MAAM,YAAY,CAAA;;AAoG3D,wBAA0D"}
|