tshy 1.0.0-3 → 1.1.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/README.md +165 -36
- package/dist/esm/add-dot.d.ts +3 -0
- package/dist/esm/add-dot.d.ts.map +1 -0
- package/dist/esm/add-dot.js +3 -0
- package/dist/esm/add-dot.js.map +1 -0
- package/dist/esm/build-commonjs.d.ts +3 -0
- package/dist/esm/build-commonjs.d.ts.map +1 -0
- package/dist/esm/build-commonjs.js +30 -0
- package/dist/esm/build-commonjs.js.map +1 -0
- package/dist/esm/build-esm.d.ts +3 -0
- package/dist/esm/build-esm.d.ts.map +1 -0
- package/dist/esm/build-esm.js +20 -0
- package/dist/esm/build-esm.js.map +1 -0
- package/dist/esm/build-fail.d.ts +6 -0
- package/dist/esm/build-fail.d.ts.map +1 -0
- package/dist/esm/build-fail.js +16 -0
- package/dist/esm/build-fail.js.map +1 -0
- package/dist/esm/build.d.ts +2 -0
- package/dist/esm/build.d.ts.map +1 -1
- package/dist/esm/build.js +37 -53
- package/dist/esm/build.js.map +1 -1
- package/dist/esm/config.d.ts.map +1 -1
- package/dist/esm/config.js +4 -61
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/exports.d.ts +4 -1
- package/dist/esm/exports.d.ts.map +1 -1
- package/dist/esm/exports.js +14 -12
- package/dist/esm/exports.js.map +1 -1
- package/dist/esm/fail.d.ts +2 -1
- package/dist/esm/fail.d.ts.map +1 -1
- package/dist/esm/fail.js +1 -1
- package/dist/esm/fail.js.map +1 -1
- package/dist/esm/imports.d.ts +5 -0
- package/dist/esm/imports.d.ts.map +1 -0
- package/dist/esm/imports.js +109 -0
- package/dist/esm/imports.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/package.d.ts +2 -2
- package/dist/esm/package.d.ts.map +1 -1
- package/dist/esm/package.js +3 -5
- package/dist/esm/package.js.map +1 -1
- package/dist/esm/resolve-export.d.ts +1 -1
- package/dist/esm/resolve-export.d.ts.map +1 -1
- package/dist/esm/resolve-export.js +10 -8
- package/dist/esm/resolve-export.js.map +1 -1
- package/dist/esm/self-dep.d.ts +4 -0
- package/dist/esm/self-dep.d.ts.map +1 -0
- package/dist/esm/self-dep.js +27 -0
- package/dist/esm/self-dep.js.map +1 -0
- package/dist/esm/set-folder-dialect.d.ts.map +1 -1
- package/dist/esm/set-folder-dialect.js +12 -6
- package/dist/esm/set-folder-dialect.js.map +1 -1
- package/dist/esm/types.d.ts +2 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/valid-dialects.d.ts +4 -0
- package/dist/esm/valid-dialects.d.ts.map +1 -0
- package/dist/esm/valid-dialects.js +14 -0
- package/dist/esm/valid-dialects.js.map +1 -0
- package/dist/esm/valid-exports.d.ts +3 -0
- package/dist/esm/valid-exports.d.ts.map +1 -0
- package/dist/esm/valid-exports.js +34 -0
- package/dist/esm/valid-exports.js.map +1 -0
- package/dist/esm/valid-external-export.d.ts +4 -0
- package/dist/esm/valid-external-export.d.ts.map +1 -0
- package/dist/esm/valid-external-export.js +12 -0
- package/dist/esm/valid-external-export.js.map +1 -0
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# tshy - TypeScript HYbridizer
|
|
2
2
|
|
|
3
|
-
Hybrid (CommonJS/ESM) TypeScript node package builder.
|
|
3
|
+
Hybrid (CommonJS/ESM) TypeScript node package builder. Write
|
|
4
|
+
modules that Just Work in ESM and CommonJS, in easy mode.
|
|
4
5
|
|
|
5
6
|
This tool manages the `exports` in your package.json file, and
|
|
6
|
-
builds your TypeScript program using `tsc` 5.2
|
|
7
|
-
|
|
7
|
+
builds your TypeScript program using `tsc` 5.2, emitting both ESM
|
|
8
|
+
and CommonJS variants, [providing the full strength of
|
|
9
|
+
TypeScript’s checking for both output
|
|
10
|
+
formats](https://twitter.com/atcb/status/1702069237710479608).
|
|
8
11
|
|
|
9
12
|
## USAGE
|
|
10
13
|
|
|
@@ -35,11 +38,11 @@ points.
|
|
|
35
38
|
|
|
36
39
|
## Configuration
|
|
37
40
|
|
|
38
|
-
Mostly, this
|
|
39
|
-
little to configure.
|
|
41
|
+
Mostly, this just uses opinionated convention, and so there is
|
|
42
|
+
very little to configure.
|
|
40
43
|
|
|
41
|
-
Source must be in `./src`. Builds are in `./dist/
|
|
42
|
-
CommonJS and `./dist/
|
|
44
|
+
Source must be in `./src`. Builds are in `./dist/commonjs` for
|
|
45
|
+
CommonJS and `./dist/esm` for ESM.
|
|
43
46
|
|
|
44
47
|
There is very little configuration for this. The only thing to
|
|
45
48
|
decide is the exported paths. If you have a `./index.ts` file,
|
|
@@ -69,12 +72,12 @@ appropriate build target locations, like:
|
|
|
69
72
|
"exports": {
|
|
70
73
|
"./foo": {
|
|
71
74
|
"import": {
|
|
72
|
-
"types": "./dist/
|
|
73
|
-
"default": "./dist/
|
|
75
|
+
"types": "./dist/esm/foo.d.ts",
|
|
76
|
+
"default": "./dist/esm/foo.js"
|
|
74
77
|
},
|
|
75
78
|
"require": {
|
|
76
|
-
"types": "./dist/
|
|
77
|
-
"default": "./dist/
|
|
79
|
+
"types": "./dist/commonjs/foo.d.ts",
|
|
80
|
+
"default": "./dist/commonjs/foo.js"
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
}
|
|
@@ -82,16 +85,27 @@ appropriate build target locations, like:
|
|
|
82
85
|
```
|
|
83
86
|
|
|
84
87
|
Any exports that are not within `./src` will not be built, and
|
|
85
|
-
can be
|
|
88
|
+
can be anything supported by package.json `exports`, as they will
|
|
89
|
+
just be passed through as-is.
|
|
86
90
|
|
|
87
91
|
```json
|
|
88
92
|
{
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
|
|
93
|
+
"tshy": {
|
|
94
|
+
"exports": {
|
|
95
|
+
".": "./src/my-built-module.ts",
|
|
96
|
+
"./package.json": "./package.json"
|
|
97
|
+
"./thing": {
|
|
98
|
+
"import": "./lib/thing.mjs",
|
|
99
|
+
"require": "./lib/thing.cjs",
|
|
100
|
+
"types": "./lib/thing.d.ts"
|
|
101
|
+
},
|
|
102
|
+
"./arraystyle": [
|
|
103
|
+
{ "import": "./no-op.js" },
|
|
104
|
+
{ "browser": "./browser-thing.js" },
|
|
105
|
+
{ "require": [{ "types": "./using-require.d.ts" }, "./using-require.js"]},
|
|
106
|
+
{ "types": "./blah.d.ts" },
|
|
107
|
+
"./etc.js"
|
|
108
|
+
]
|
|
95
109
|
}
|
|
96
110
|
}
|
|
97
111
|
}
|
|
@@ -137,7 +151,7 @@ To do this, create a polyfill file with the CommonJS code in
|
|
|
137
151
|
```js
|
|
138
152
|
// src/source-dir-cjs.cts
|
|
139
153
|
// ^^^^^^^^^^--------- matching name
|
|
140
|
-
// ^^^^----- "-
|
|
154
|
+
// ^^^^----- "-cjs" tag
|
|
141
155
|
// ^^^^- ".cts" filename suffix
|
|
142
156
|
// this one has a -cjs.cts suffix, so it will override the
|
|
143
157
|
// module at src/source-dir.ts in the CJS build,
|
|
@@ -149,23 +163,28 @@ export const sourceDir = pathToFileURL(__dirname)
|
|
|
149
163
|
|
|
150
164
|
Then put the "real" ESM code in `<name>.ts` (not `.mts`!)
|
|
151
165
|
|
|
166
|
+
You will generally have to `//@ts-ignore` a bunch of stuff to get
|
|
167
|
+
the CommonJS build to ignore it, so it's best to keep the
|
|
168
|
+
polyfill surface as small as possible.
|
|
169
|
+
|
|
152
170
|
```js
|
|
153
171
|
// src/source-dir.ts
|
|
154
172
|
// This is the ESM version of the module
|
|
173
|
+
//@ts-ignore
|
|
155
174
|
export const sourceDir = new URL('.', import.meta.url)
|
|
156
175
|
```
|
|
157
176
|
|
|
158
177
|
Then in your code, you can just `import { sourceDir } from
|
|
159
|
-
'./source-dir.js'` and it'll work in both
|
|
178
|
+
'./source-dir.js'` and it'll work in both builds.
|
|
160
179
|
|
|
161
|
-
## `.cts` and `.mts` files
|
|
180
|
+
## Excluding from a build using `.cts` and `.mts` files
|
|
162
181
|
|
|
163
182
|
Files named `*.mts` will be excluded from the CommonJS build.
|
|
164
183
|
|
|
165
184
|
Files named `*.cts` will be excluded from the ESM build.
|
|
166
185
|
|
|
167
|
-
If you need to do something one way for
|
|
168
|
-
|
|
186
|
+
If you need to do something one way for CommonJS and another way for
|
|
187
|
+
esm, use the "Dialect Switching" trick, with the ESM code living
|
|
169
188
|
in `src/<whatever>.ts` and the CommonJS polyfill living in
|
|
170
189
|
`src/<whatever>-cjs.cts`.
|
|
171
190
|
|
|
@@ -195,17 +214,6 @@ If you don't provide that config, then the default is:
|
|
|
195
214
|
}
|
|
196
215
|
```
|
|
197
216
|
|
|
198
|
-
## Package `#imports`
|
|
199
|
-
|
|
200
|
-
Using the `imports` field in `package.json` is not currently
|
|
201
|
-
supported, because this looks at the nearest `package.json` to
|
|
202
|
-
get local imports, and the package.json files placed in
|
|
203
|
-
`dist/{cjs,mjs}` can't have local imports outside of their
|
|
204
|
-
folders.
|
|
205
|
-
|
|
206
|
-
There's a way it could theoretically be done, but it's a bit
|
|
207
|
-
complicated. A future version may support this.
|
|
208
|
-
|
|
209
217
|
## TSConfigs
|
|
210
218
|
|
|
211
219
|
Put whatever configuration you want in `tsconfig.json`, with the
|
|
@@ -225,12 +233,12 @@ If you don't have a `tsconfig.json` file, then one will be
|
|
|
225
233
|
provided for you.
|
|
226
234
|
|
|
227
235
|
Then the `tsconfig.json` file will be used as the default project
|
|
228
|
-
for code hints in VSCode
|
|
236
|
+
for code hints in VSCode, neovim, tests, etc.
|
|
229
237
|
|
|
230
238
|
## `src/package.json`
|
|
231
239
|
|
|
232
240
|
As of TypeScript 5.2, the only way to emit JavaScript to ESM or
|
|
233
|
-
|
|
241
|
+
cjs, and also import packages using node-style `"exports"`-aware
|
|
234
242
|
module resolution, is to set the `type` field in the
|
|
235
243
|
`package.json` file closest to the TypeScript source code.
|
|
236
244
|
|
|
@@ -238,3 +246,124 @@ During the build, `tshy` will create a file at `src/package.json`
|
|
|
238
246
|
for this purpose, and then delete it afterwards. If that file
|
|
239
247
|
exists and _wasn't_ put there by `tshy`, then it will be
|
|
240
248
|
destroyed.
|
|
249
|
+
|
|
250
|
+
## Package `#imports`
|
|
251
|
+
|
|
252
|
+
If you use `"imports"` in your package.json, then tshy will set
|
|
253
|
+
`scripts.preinstall` to set up some symbolic links to make it
|
|
254
|
+
work. This just means you can't use `scripts.preinstall` for
|
|
255
|
+
anything else if you use `"imports"`.
|
|
256
|
+
|
|
257
|
+
<details>
|
|
258
|
+
<summary>tl;dr explanation</summary>
|
|
259
|
+
|
|
260
|
+
The `"imports"` field in package.json allows you to set local
|
|
261
|
+
package imports, which have the same kind of conditional import
|
|
262
|
+
logic as `"exports"`. This is especially useful when you have a
|
|
263
|
+
vendored dependency with `require` and `import` variants, modules
|
|
264
|
+
that have to be bundled in different ways for different
|
|
265
|
+
environments, or different dependencies for different
|
|
266
|
+
environments.
|
|
267
|
+
|
|
268
|
+
These package imports are _always_ resolved against the nearest
|
|
269
|
+
`package.json` file, and tshy uses generated package.json files
|
|
270
|
+
to set the module dialect to `"type":"module"` in `dist/esm` and
|
|
271
|
+
`"type":"commonjs"` in `dist/commonjs`, and it swaps the
|
|
272
|
+
`src/package.json` file between this during the `tsc` builds.
|
|
273
|
+
|
|
274
|
+
Furthermore, local package imports may not be relative files
|
|
275
|
+
outside the package folder. They may only be local files within
|
|
276
|
+
the local package, or dependencies resolved in `node_modules`.
|
|
277
|
+
|
|
278
|
+
To support this, tshy copies the `imports` field from the
|
|
279
|
+
project's package.json into these dialect-setting generated
|
|
280
|
+
package.json files, and creates symlinks into the appropriate
|
|
281
|
+
places so that they resolve to the same files on disk.
|
|
282
|
+
|
|
283
|
+
Because symlinks may not be included in npm packages (and even if
|
|
284
|
+
they are included, they won't be unpacked at install time), the
|
|
285
|
+
symlinks it places in `./dist` wouldn't do much good. In order to
|
|
286
|
+
work around _this_ restriction, tshy creates a node program at
|
|
287
|
+
`dist/.tshy-link-imports.mjs`, which generates the symlinks at
|
|
288
|
+
install time via the `preinstall` script.
|
|
289
|
+
|
|
290
|
+
</details>
|
|
291
|
+
|
|
292
|
+
## Local Package `exports`
|
|
293
|
+
|
|
294
|
+
In order to facilitate local package exports, tshy will create a
|
|
295
|
+
symlink to the current package temporarily in
|
|
296
|
+
`./src/node_modules` and permanently in `./dist/node_modules`.
|
|
297
|
+
|
|
298
|
+
If you rely on this feature, you may need to add a `paths`
|
|
299
|
+
section to your `tsconfig.json` so that you don't get nagged
|
|
300
|
+
constantly by your editor about missing type references.
|
|
301
|
+
|
|
302
|
+
<details>
|
|
303
|
+
<summary>tl;dr explanation</summary>
|
|
304
|
+
|
|
305
|
+
Similar to local module imports, Node supports importing the
|
|
306
|
+
`exports` of the current package as if it was a dependency of
|
|
307
|
+
itself. The generated `package.json` files mess with this similar
|
|
308
|
+
to `imports`, but it's much easier to work around.
|
|
309
|
+
|
|
310
|
+
For example, if you had this in your package.json:
|
|
311
|
+
|
|
312
|
+
```json
|
|
313
|
+
{
|
|
314
|
+
"name": "@my/package",
|
|
315
|
+
"exports": {
|
|
316
|
+
"./foo": {
|
|
317
|
+
"import": "./lib/foo.mjs",
|
|
318
|
+
"require": "./lib/foo.cjs"
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Then any module in the package could do
|
|
325
|
+
`import('@my/package/foo')` or `require('@my/package/foo')` to
|
|
326
|
+
pull in the appropriate file.
|
|
327
|
+
|
|
328
|
+
In order to make this wort, tshy links the current project
|
|
329
|
+
directory into `./src/node_modules/<pkgname>` during the builds,
|
|
330
|
+
and removes the link afterwards, so that TypeScript knows what
|
|
331
|
+
those things refer to.
|
|
332
|
+
|
|
333
|
+
The link is also created in the `dist` folder, but it's only
|
|
334
|
+
relevant if your tests load the code from `./dist` rather than
|
|
335
|
+
from `./src`. In the install, there's no need to re-create this
|
|
336
|
+
link, because the package will be in a `node_modules` folder
|
|
337
|
+
already.
|
|
338
|
+
|
|
339
|
+
If you use this feature, you can put something like this in your
|
|
340
|
+
`tsconfig.json` file so that your editor knows what those things
|
|
341
|
+
refer to:
|
|
342
|
+
|
|
343
|
+
```json
|
|
344
|
+
{
|
|
345
|
+
"compilerOptions": {
|
|
346
|
+
"paths": {
|
|
347
|
+
"@my/package/foo": ["./src/foo.js"],
|
|
348
|
+
"@my/package/bar": ["./src/bar.js"]
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Note the `.js` extension, rather than `.ts`. Add this for each
|
|
355
|
+
submodule path that you use in this way, or use a wildcard if you
|
|
356
|
+
prefer, though this might result in failing to catch errors if
|
|
357
|
+
you use a submodule identifier that isn't actually exported:
|
|
358
|
+
|
|
359
|
+
```json
|
|
360
|
+
{
|
|
361
|
+
"compilerOptions": {
|
|
362
|
+
"paths": {
|
|
363
|
+
"@my/package/*": ["./src/*.js"]
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
</details>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-dot.d.ts","sourceRoot":"","sources":["../../src/add-dot.ts"],"names":[],"mappings":"4BACmB,MAAM;AAAzB,wBAA4C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-dot.js","sourceRoot":"","sources":["../../src/add-dot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,eAAe,CAAC,CAAS,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA","sourcesContent":["import { join } from 'node:path/posix'\nexport default (s: string) => `./${join(s)}`\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-commonjs.d.ts","sourceRoot":"","sources":["../../src/build-commonjs.ts"],"names":[],"mappings":"AAQA,OAAO,eAAe,CAAA;AAEtB,eAAO,MAAM,aAAa,iBAwBzB,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 buildFail from './build-fail.js';
|
|
6
|
+
import * as console from './console.js';
|
|
7
|
+
import polyfills from './polyfills.js';
|
|
8
|
+
import setFolderDialect from './set-folder-dialect.js';
|
|
9
|
+
import './tsconfig.js';
|
|
10
|
+
export const buildCommonJS = () => {
|
|
11
|
+
console.debug(chalk.cyan.dim('building commonjs'));
|
|
12
|
+
setFolderDialect('src', 'commonjs');
|
|
13
|
+
const res = spawnSync('tsc -p .tshy/commonjs.json', {
|
|
14
|
+
shell: true,
|
|
15
|
+
stdio: 'inherit',
|
|
16
|
+
});
|
|
17
|
+
setFolderDialect('src');
|
|
18
|
+
if (res.status || res.signal)
|
|
19
|
+
return buildFail(res);
|
|
20
|
+
setFolderDialect('.tshy-build-tmp/commonjs', 'commonjs');
|
|
21
|
+
console.error(chalk.cyan.bold('built commonjs'));
|
|
22
|
+
// apply polyfills
|
|
23
|
+
for (const [f, t] of polyfills.entries()) {
|
|
24
|
+
const stemFrom = resolve('.tshy-build-tmp/commonjs', relative(resolve('src'), resolve(f))).replace(/\.cts$/, '');
|
|
25
|
+
const stemTo = resolve('.tshy-build-tmp/commonjs', relative(resolve('src'), resolve(t))).replace(/\.tsx?$/, '');
|
|
26
|
+
renameSync(`${stemFrom}.cjs`, `${stemTo}.js`);
|
|
27
|
+
renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=build-commonjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-commonjs.js","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AAC,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,SAAS,EAAE,EAAE,CAAC,CAAA;QACxB,UAAU,CAAC,GAAG,QAAQ,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,CAAA;QAC7C,UAAU,CAAC,GAAG,QAAQ,QAAQ,EAAE,GAAG,MAAM,OAAO,CAAC,CAAA;KAClD;AACH,CAAC,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { spawnSync } from 'node:child_process'\nimport { renameSync } from 'node:fs'\nimport { relative, resolve } from 'node:path/posix'\nimport buildFail from './build-fail.js'\nimport * as console from './console.js'\nimport polyfills from './polyfills.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport './tsconfig.js'\n\nexport const buildCommonJS = () => {\n console.debug(chalk.cyan.dim('building 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) return buildFail(res)\n setFolderDialect('.tshy-build-tmp/commonjs', 'commonjs')\n console.error(chalk.cyan.bold('built commonjs'))\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(/\\.tsx?$/, '')\n renameSync(`${stemFrom}.cjs`, `${stemTo}.js`)\n renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`)\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-esm.d.ts","sourceRoot":"","sources":["../../src/build-esm.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,CAAA;AAEtB,eAAO,MAAM,QAAQ,iBAWpB,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import buildFail from './build-fail.js';
|
|
4
|
+
import * as console from './console.js';
|
|
5
|
+
import setFolderDialect from './set-folder-dialect.js';
|
|
6
|
+
import './tsconfig.js';
|
|
7
|
+
export const buildESM = () => {
|
|
8
|
+
console.debug(chalk.cyan.dim('building esm'));
|
|
9
|
+
setFolderDialect('src', 'esm');
|
|
10
|
+
const res = spawnSync('tsc -p .tshy/esm.json', {
|
|
11
|
+
shell: true,
|
|
12
|
+
stdio: 'inherit',
|
|
13
|
+
});
|
|
14
|
+
setFolderDialect('src');
|
|
15
|
+
if (res.status || res.signal)
|
|
16
|
+
return buildFail(res);
|
|
17
|
+
setFolderDialect('.tshy-build-tmp/esm', 'esm');
|
|
18
|
+
console.error(chalk.cyan.bold('built esm'));
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=build-esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-esm.js","sourceRoot":"","sources":["../../src/build-esm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,gBAAgB,MAAM,yBAAyB,CAAA;AACtD,OAAO,eAAe,CAAA;AAEtB,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAA;IAC7C,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC9B,MAAM,GAAG,GAAG,SAAS,CAAC,uBAAuB,EAAE;QAC7C,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;KACjB,CAAC,CAAA;IACF,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACvB,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC,GAAG,CAAC,CAAA;IACnD,gBAAgB,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAA;IAC9C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAA;AAC7C,CAAC,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { spawnSync } from 'node:child_process'\nimport buildFail from './build-fail.js'\nimport * as console from './console.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport './tsconfig.js'\n\nexport const buildESM = () => {\n console.debug(chalk.cyan.dim('building 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) return buildFail(res)\n setFolderDialect('.tshy-build-tmp/esm', 'esm')\n console.error(chalk.cyan.bold('built esm'))\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { SpawnSyncReturns } from 'node:child_process';
|
|
3
|
+
import './tsconfig.js';
|
|
4
|
+
declare const _default: (res: SpawnSyncReturns<Buffer>) => never;
|
|
5
|
+
export default _default;
|
|
6
|
+
//# sourceMappingURL=build-fail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-fail.d.ts","sourceRoot":"","sources":["../../src/build-fail.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAIrD,OAAO,eAAe,CAAA;8BAKD,iBAAiB,MAAM,CAAC;AAA7C,wBAOC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as console from './console.js';
|
|
2
|
+
import fail from './fail.js';
|
|
3
|
+
import setFolderDialect from './set-folder-dialect.js';
|
|
4
|
+
import './tsconfig.js';
|
|
5
|
+
import { unlink as unlinkImports } from './imports.js';
|
|
6
|
+
import { unlink as unlinkSelfDep } from './self-dep.js';
|
|
7
|
+
import pkg from './package.js';
|
|
8
|
+
export default (res) => {
|
|
9
|
+
setFolderDialect('src');
|
|
10
|
+
unlinkImports(pkg, 'src');
|
|
11
|
+
unlinkSelfDep(pkg, 'src');
|
|
12
|
+
fail('build failed');
|
|
13
|
+
console.error(res);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=build-fail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-fail.js","sourceRoot":"","sources":["../../src/build-fail.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,gBAAgB,MAAM,yBAAyB,CAAA;AACtD,OAAO,eAAe,CAAA;AACtB,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,GAAG,MAAM,cAAc,CAAA;AAE9B,eAAe,CAAC,GAA6B,EAAE,EAAE;IAC/C,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACvB,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACzB,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACzB,IAAI,CAAC,cAAc,CAAC,CAAA;IACpB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAA","sourcesContent":["import { SpawnSyncReturns } from 'node:child_process'\nimport * as console from './console.js'\nimport fail from './fail.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport './tsconfig.js'\nimport { unlink as unlinkImports } from './imports.js'\nimport { unlink as unlinkSelfDep } from './self-dep.js'\nimport pkg from './package.js'\n\nexport default (res: SpawnSyncReturns<Buffer>) => {\n setFolderDialect('src')\n unlinkImports(pkg, 'src')\n unlinkSelfDep(pkg, 'src')\n fail('build failed')\n console.error(res)\n process.exit(1)\n}\n"]}
|
package/dist/esm/build.d.ts
CHANGED
package/dist/esm/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAkBA,OAAO,eAAe,CAAA;;AAGtB,wBAmCC"}
|
package/dist/esm/build.js
CHANGED
|
@@ -1,63 +1,47 @@
|
|
|
1
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
2
|
import { rimrafSync } from 'rimraf';
|
|
6
3
|
import { syncContentSync } from 'sync-content';
|
|
7
4
|
import bins from './bins.js';
|
|
5
|
+
import { buildCommonJS } from './build-commonjs.js';
|
|
6
|
+
import { buildESM } from './build-esm.js';
|
|
8
7
|
import * as console from './console.js';
|
|
9
8
|
import dialects from './dialects.js';
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import
|
|
9
|
+
import { link as linkImports, save as saveImports, unlink as unlinkImports, } from './imports.js';
|
|
10
|
+
import pkg from './package.js';
|
|
11
|
+
import { link as linkSelfDep, unlink as unlinkSelfDep, } from './self-dep.js';
|
|
13
12
|
import './tsconfig.js';
|
|
14
13
|
import writePackage from './write-package.js';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
setFolderDialect('src');
|
|
43
|
-
if (res.status || res.signal)
|
|
44
|
-
buildFail(res);
|
|
45
|
-
setFolderDialect('.tshy-build-tmp/commonjs', 'commonjs');
|
|
46
|
-
console.error(chalk.cyan.bold('built commonjs'));
|
|
47
|
-
// apply polyfills
|
|
48
|
-
for (const [f, t] of polyfills.entries()) {
|
|
49
|
-
const stemFrom = resolve('.tshy-build-tmp/commonjs', relative(resolve('src'), resolve(f))).replace(/\.cts$/, '');
|
|
50
|
-
const stemTo = resolve('.tshy-build-tmp/commonjs', relative(resolve('src'), resolve(t))).replace(/\.tsx?$/, '');
|
|
51
|
-
renameSync(`${stemFrom}.cjs`, `${stemTo}.js`);
|
|
52
|
-
renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`);
|
|
14
|
+
export default async () => {
|
|
15
|
+
rimrafSync('.tshy-build-tmp');
|
|
16
|
+
linkSelfDep(pkg, 'src');
|
|
17
|
+
await linkImports(pkg, 'src');
|
|
18
|
+
if (dialects.includes('esm'))
|
|
19
|
+
buildESM();
|
|
20
|
+
if (dialects.includes('commonjs'))
|
|
21
|
+
buildCommonJS();
|
|
22
|
+
await unlinkImports(pkg, 'src');
|
|
23
|
+
unlinkSelfDep(pkg, 'src');
|
|
24
|
+
console.debug(chalk.cyan.dim('moving to ./dist'));
|
|
25
|
+
syncContentSync('.tshy-build-tmp', 'dist');
|
|
26
|
+
console.debug(chalk.cyan.dim('removing build temp dir'));
|
|
27
|
+
rimrafSync('.tshy-build-tmp');
|
|
28
|
+
linkSelfDep(pkg, 'dist');
|
|
29
|
+
if (pkg.imports) {
|
|
30
|
+
console.debug('linking package imports', pkg.imports);
|
|
31
|
+
if (dialects.includes('commonjs'))
|
|
32
|
+
await linkImports(pkg, 'dist/commonjs', true);
|
|
33
|
+
if (dialects.includes('esm'))
|
|
34
|
+
await linkImports(pkg, 'dist/esm', true);
|
|
35
|
+
if (saveImports('dist/.tshy-link-imports.mjs')) {
|
|
36
|
+
pkg.scripts = pkg.scripts || {};
|
|
37
|
+
pkg.scripts.preinstall =
|
|
38
|
+
'node -e "import(process.argv[1]).catch(()=>{})" ' +
|
|
39
|
+
'dist/.tshy-link-imports.mjs';
|
|
40
|
+
}
|
|
53
41
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
console.debug(chalk.cyan.dim('chmod bins'));
|
|
60
|
-
bins();
|
|
61
|
-
console.debug(chalk.cyan.dim('write package.json'));
|
|
62
|
-
writePackage();
|
|
42
|
+
console.debug(chalk.cyan.dim('chmod bins'));
|
|
43
|
+
bins();
|
|
44
|
+
console.debug(chalk.cyan.dim('write package.json'));
|
|
45
|
+
writePackage();
|
|
46
|
+
};
|
|
63
47
|
//# sourceMappingURL=build.js.map
|
package/dist/esm/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,E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AAE;QACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;QACrD,IAAI,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;YAC/B,MAAM,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,CAAC,CAAA;QAC/C,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;YAC1B,MAAM,WAAW,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,CAAA;QAC1C,IAAI,WAAW,CAAC,6BAA6B,CAAC,EAAE;YAC9C,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAA;YAC/B,GAAG,CAAC,OAAO,CAAC,UAAU;gBACpB,kDAAkD;oBAClD,6BAA6B,CAAA;SAChC;KACF;IAED,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAA;IAC3C,IAAI,EAAE,CAAA;IACN,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAA;IACnD,YAAY,EAAE,CAAA;AAChB,CAAC,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { rimrafSync } from 'rimraf'\nimport { syncContentSync } from 'sync-content'\nimport bins from './bins.js'\nimport { buildCommonJS } from './build-commonjs.js'\nimport { buildESM } from './build-esm.js'\nimport * as console from './console.js'\nimport dialects from './dialects.js'\nimport {\n link as linkImports,\n save as saveImports,\n unlink as unlinkImports,\n} from './imports.js'\nimport pkg from './package.js'\nimport {\n link as linkSelfDep,\n unlink as unlinkSelfDep,\n} from './self-dep.js'\nimport './tsconfig.js'\nimport writePackage from './write-package.js'\n\nexport default async () => {\n rimrafSync('.tshy-build-tmp')\n\n linkSelfDep(pkg, 'src')\n await linkImports(pkg, 'src')\n if (dialects.includes('esm')) buildESM()\n if (dialects.includes('commonjs')) buildCommonJS()\n await unlinkImports(pkg, 'src')\n unlinkSelfDep(pkg, 'src')\n\n console.debug(chalk.cyan.dim('moving to ./dist'))\n syncContentSync('.tshy-build-tmp', 'dist')\n console.debug(chalk.cyan.dim('removing build temp dir'))\n rimrafSync('.tshy-build-tmp')\n\n linkSelfDep(pkg, 'dist')\n\n if (pkg.imports) {\n console.debug('linking package imports', pkg.imports)\n if (dialects.includes('commonjs'))\n await linkImports(pkg, 'dist/commonjs', true)\n if (dialects.includes('esm'))\n await linkImports(pkg, 'dist/esm', true)\n if (saveImports('dist/.tshy-link-imports.mjs')) {\n pkg.scripts = pkg.scripts || {}\n pkg.scripts.preinstall =\n 'node -e \"import(process.argv[1]).catch(()=>{})\" ' +\n 'dist/.tshy-link-imports.mjs'\n }\n }\n\n console.debug(chalk.cyan.dim('chmod bins'))\n bins()\n console.debug(chalk.cyan.dim('write package.json'))\n writePackage()\n}\n"]}
|
package/dist/esm/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAIA,OAAO,EAAW,UAAU,EAAE,MAAM,YAAY,CAAA;AA8BhD,QAAA,MAAM,MAAM,EAAE,UAAoC,CAAA;AAClD,eAAe,MAAM,CAAA"}
|