@tamagui/build 2.0.0-rc.3 → 2.0.0-rc.30
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/.turbo/turbo-test.log +97 -15
- package/README.md +4 -2
- package/__tests__/fixtures/js-main-package/.turbo/turbo-build.log +2 -0
- package/__tests__/fixtures/js-main-package/LICENSE +1 -0
- package/__tests__/fixtures/js-main-package/dist/cjs/index.js +21 -0
- package/__tests__/fixtures/js-main-package/dist/cjs/index.js.map +6 -0
- package/__tests__/fixtures/js-main-package/dist/cjs/index.native.js +29 -0
- package/__tests__/fixtures/js-main-package/dist/cjs/index.native.js.map +1 -0
- package/__tests__/fixtures/js-main-package/dist/esm/index.mjs +3 -0
- package/__tests__/fixtures/js-main-package/dist/esm/index.mjs.map +1 -0
- package/__tests__/fixtures/js-main-package/dist/esm/index.native.js +3 -0
- package/__tests__/fixtures/js-main-package/dist/esm/index.native.js.map +1 -0
- package/__tests__/fixtures/js-main-package/package.json +14 -0
- package/__tests__/fixtures/js-main-package/src/index.ts +1 -0
- package/__tests__/fixtures/js-main-package/tsconfig.json +13 -0
- package/__tests__/fixtures/js-main-package/types/index.d.ts +2 -0
- package/__tests__/fixtures/js-main-package/types/index.d.ts.map +1 -0
- package/__tests__/fixtures/simple-package/.turbo/turbo-build.log +1 -1
- package/__tests__/fixtures/simple-package/package.json +3 -1
- package/__tests__/fixtures/simple-package/src/index.ts +2 -0
- package/__tests__/fixtures/simple-package/src/nested/index.ts +1 -0
- package/__tests__/fixtures/watch-package/.turbo/turbo-build.log +1 -1
- package/__tests__/integration.test.ts +82 -3
- package/package.json +13 -6
- package/pretty-print-errors.js +33 -0
- package/tamagui-build.js +176 -53
package/.turbo/turbo-test.log
CHANGED
|
@@ -5,31 +5,113 @@ $ vitest --run
|
|
|
5
5
|
$ node ../../../tamagui-build.js
|
|
6
6
|
$ node ../../../tamagui-build.js --bundle
|
|
7
7
|
$ node ../../../tamagui-build.js --skip-mjs
|
|
8
|
+
$ node ../../../tamagui-build.js --skip-sourcemaps
|
|
8
9
|
$ node ../../../tamagui-build.js --ignore-base-url
|
|
9
10
|
[90mstdout[2m | __tests__/integration.test.ts[2m > [22m[2mtamagui-build integration test[2m > [22m[2mshould rebuild the package on file change when --watch is used
|
|
10
|
-
[22m[39mWatch process output: built tamagui-build-test-watch-package in
|
|
11
|
+
[22m[39mWatch process output: built tamagui-build-test-watch-package in 79 ms
|
|
11
12
|
|
|
12
13
|
Initial build complete, modifying file...
|
|
13
14
|
|
|
14
15
|
[90mstdout[2m | __tests__/integration.test.ts[2m > [22m[2mtamagui-build integration test[2m > [22m[2mshould rebuild the package on file change when --watch is used
|
|
15
|
-
[22m[39mWatch process output: built tamagui-build-test-watch-package in
|
|
16
|
+
[22m[39mWatch process output: built tamagui-build-test-watch-package in 348 ms
|
|
16
17
|
|
|
17
18
|
Rebuild after file modification complete
|
|
18
19
|
|
|
19
20
|
$ node ../../../tamagui-build.js
|
|
20
21
|
$ node ../../../tamagui-build.js
|
|
21
22
|
$ MINIFY=true node ../../../tamagui-build.js
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[2m
|
|
32
|
-
[
|
|
33
|
-
[2m
|
|
34
|
-
[
|
|
23
|
+
$ node ../../../tamagui-build.js
|
|
24
|
+
$ node ../../../tamagui-build.js
|
|
25
|
+
$ node ../../../tamagui-build.js
|
|
26
|
+
$ node ../../../tamagui-build.js
|
|
27
|
+
[31m❯[39m __tests__/integration.test.ts [2m([22m[2m11 tests[22m[2m | [22m[31m4 failed[39m[2m)[22m[33m 8732[2mms[22m[39m
|
|
28
|
+
[31m [31m×[31m should build the package correctly[39m[33m 647[2mms[22m[39m
|
|
29
|
+
[31m [31m×[31m should bundle the package correctly[39m[33m 549[2mms[22m[39m
|
|
30
|
+
[31m [31m×[31m should skip mjs files when --skip-mjs is used[39m[33m 611[2mms[22m[39m
|
|
31
|
+
[33m[2m✓[22m[39m should skip sourcemaps when --skip-sourcemaps is used [33m 620[2mms[22m[39m
|
|
32
|
+
[33m[2m✓[22m[39m should ignore base URL when --ignore-base-url is used [33m 621[2mms[22m[39m
|
|
33
|
+
[33m[2m✓[22m[39m should rebuild the package on file change when --watch is used [33m 752[2mms[22m[39m
|
|
34
|
+
[33m[2m✓[22m[39m should generate correct platform-specific output [33m 617[2mms[22m[39m
|
|
35
|
+
[33m[2m✓[22m[39m should minify the output when MINIFY=true is set [33m 1267[2mms[22m[39m
|
|
36
|
+
[33m[2m✓[22m[39m should clean stale outputs before building [33m 1250[2mms[22m[39m
|
|
37
|
+
[31m [31m×[31m should keep only the required js aliases after postprocessing[39m[33m 631[2mms[22m[39m
|
|
38
|
+
[33m[2m✓[22m[39m should keep explicit cjs .js mains as final output [33m 1133[2mms[22m[39m
|
|
39
|
+
|
|
40
|
+
[31m⎯⎯⎯⎯⎯⎯⎯[39m[1m[41m Failed Tests 4 [49m[22m[31m⎯⎯⎯⎯⎯⎯⎯[39m
|
|
41
|
+
|
|
42
|
+
[41m[1m FAIL [22m[49m __tests__/integration.test.ts[2m > [22mtamagui-build integration test[2m > [22mshould build the package correctly
|
|
43
|
+
[31m[1mAssertionError[22m: expected false to be true // Object.is equality[39m
|
|
44
|
+
|
|
45
|
+
[32m- Expected[39m
|
|
46
|
+
[31m+ Received[39m
|
|
47
|
+
|
|
48
|
+
[32m- true[39m
|
|
49
|
+
[31m+ false[39m
|
|
50
|
+
|
|
51
|
+
[36m [2m❯[22m __tests__/integration.test.ts:[2m50:59[22m[39m
|
|
52
|
+
[90m 48| [39m [34mexpect[39m(esmOutput)[33m.[39m[34mtoContain[39m([32m'Hello,'[39m)
|
|
53
|
+
[90m 49| [39m [34mexpect[39m(esmOutput)[33m.[39m[34mtoContain[39m([32m"./nested/index.mjs"[39m)
|
|
54
|
+
[90m 50| [39m [34mexpect[39m([34mexistsSync[39m([34mjoin[39m(distPath[33m,[39m [32m'cjs'[39m[33m,[39m [32m'index.js'[39m)))[33m.[39m[34mtoBe[39m([35mtrue[39m)
|
|
55
|
+
[90m | [39m [31m^[39m
|
|
56
|
+
[90m 51| [39m [34mexpect[39m([34mexistsSync[39m([34mjoin[39m(distPath[33m,[39m [32m'esm'[39m[33m,[39m [32m'index.js'[39m)))[33m.[39m[34mtoBe[39m([35mtrue[39m)
|
|
57
|
+
[90m 52| [39m [34mexpect[39m([34mexistsSync[39m([34mjoin[39m(distPath[33m,[39m [32m'jsx'[39m[33m,[39m [32m'index.js'[39m)))[33m.[39m[34mtoBe[39m([35mtrue[39m)
|
|
58
|
+
|
|
59
|
+
[31m[2m⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/4]⎯[22m[39m
|
|
60
|
+
|
|
61
|
+
[41m[1m FAIL [22m[49m __tests__/integration.test.ts[2m > [22mtamagui-build integration test[2m > [22mshould bundle the package correctly
|
|
62
|
+
[31m[1mAssertionError[22m: expected false to be true // Object.is equality[39m
|
|
63
|
+
|
|
64
|
+
[32m- Expected[39m
|
|
65
|
+
[31m+ Received[39m
|
|
66
|
+
|
|
67
|
+
[32m- true[39m
|
|
68
|
+
[31m+ false[39m
|
|
69
|
+
|
|
70
|
+
[36m [2m❯[22m __tests__/integration.test.ts:[2m67:59[22m[39m
|
|
71
|
+
[90m 65| [39m [34mexpect[39m(cjsOutput)[33m.[39m[34mtoContain[39m([32m'Hello,'[39m)
|
|
72
|
+
[90m 66| [39m [34mexpect[39m(esmOutput)[33m.[39m[34mtoContain[39m([32m'Hello,'[39m)
|
|
73
|
+
[90m 67| [39m [34mexpect[39m([34mexistsSync[39m([34mjoin[39m(distPath[33m,[39m [32m'cjs'[39m[33m,[39m [32m'index.js'[39m)))[33m.[39m[34mtoBe[39m([35mtrue[39m)
|
|
74
|
+
[90m | [39m [31m^[39m
|
|
75
|
+
[90m 68| [39m [34mexpect[39m([34mexistsSync[39m([34mjoin[39m(distPath[33m,[39m [32m'esm'[39m[33m,[39m [32m'index.js'[39m)))[33m.[39m[34mtoBe[39m([35mtrue[39m)
|
|
76
|
+
[90m 69| [39m [34mexpect[39m([34mexistsSync[39m([34mjoin[39m(distPath[33m,[39m [32m'jsx'[39m[33m,[39m [32m'index.js'[39m)))[33m.[39m[34mtoBe[39m([35mtrue[39m)
|
|
77
|
+
|
|
78
|
+
[31m[2m⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/4]⎯[22m[39m
|
|
79
|
+
|
|
80
|
+
[41m[1m FAIL [22m[49m __tests__/integration.test.ts[2m > [22mtamagui-build integration test[2m > [22mshould skip mjs files when --skip-mjs is used
|
|
81
|
+
[31m[1mAssertionError[22m: expected false to be true // Object.is equality[39m
|
|
82
|
+
|
|
83
|
+
[32m- Expected[39m
|
|
84
|
+
[31m+ Received[39m
|
|
85
|
+
|
|
86
|
+
[32m- true[39m
|
|
87
|
+
[31m+ false[39m
|
|
88
|
+
|
|
89
|
+
[36m [2m❯[22m __tests__/integration.test.ts:[2m79:59[22m[39m
|
|
90
|
+
[90m 77| [39m [34mexpect[39m([34mexistsSync[39m(distCjsFilePath))[33m.[39m[34mtoBe[39m([35mtrue[39m)
|
|
91
|
+
[90m 78| [39m [34mexpect[39m([34mexistsSync[39m(distEsmFilePath))[33m.[39m[34mtoBe[39m([35mfalse[39m)
|
|
92
|
+
[90m 79| [39m [34mexpect[39m([34mexistsSync[39m([34mjoin[39m(distPath[33m,[39m [32m'cjs'[39m[33m,[39m [32m'index.js'[39m)))[33m.[39m[34mtoBe[39m([35mtrue[39m)
|
|
93
|
+
[90m | [39m [31m^[39m
|
|
94
|
+
[90m 80| [39m })
|
|
95
|
+
[90m 81| [39m
|
|
96
|
+
|
|
97
|
+
[31m[2m⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/4]⎯[22m[39m
|
|
98
|
+
|
|
99
|
+
[41m[1m FAIL [22m[49m __tests__/integration.test.ts[2m > [22mtamagui-build integration test[2m > [22mshould keep only the required js aliases after postprocessing
|
|
100
|
+
[31m[1mAssertionError[22m: expected [ 'cjs/index.cjs', …(25) ] to include 'cjs/index.js'[39m
|
|
101
|
+
[36m [2m❯[22m __tests__/integration.test.ts:[2m250:23[22m[39m
|
|
102
|
+
[90m248| [39m [33m.[39m[34mmap[39m((file) [33m=>[39m file[33m.[39m[34mreplace[39m([36m/^dist\//[39m[33m,[39m [32m''[39m))
|
|
103
|
+
[90m249| [39m
|
|
104
|
+
[90m250| [39m [34mexpect[39m(distFiles)[33m.[39m[34mtoContain[39m([32m'cjs/index.js'[39m)
|
|
105
|
+
[90m | [39m [31m^[39m
|
|
106
|
+
[90m251| [39m [34mexpect[39m(distFiles)[33m.[39m[34mtoContain[39m([32m'esm/index.js'[39m)
|
|
107
|
+
[90m252| [39m [34mexpect[39m(distFiles)[33m.[39m[34mtoContain[39m([32m'esm/index.js.map'[39m)
|
|
108
|
+
|
|
109
|
+
[31m[2m⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/4]⎯[22m[39m
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
[2m Test Files [22m [1m[31m1 failed[39m[22m[90m (1)[39m
|
|
113
|
+
[2m Tests [22m [1m[31m4 failed[39m[22m[2m | [22m[1m[32m7 passed[39m[22m[90m (11)[39m
|
|
114
|
+
[2m Start at [22m 17:18:05
|
|
115
|
+
[2m Duration [22m 8.85s[2m (transform 35ms, setup 0ms, collect 42ms, tests 8.73s, environment 0ms, prepare 3ms)[22m
|
|
35
116
|
|
|
117
|
+
error: script "test" exited with code 1
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Some details on how it works:
|
|
|
14
14
|
- in `.mjs`, adds path-specific imports to non-specific imports
|
|
15
15
|
- outputs both `.js` and `.cjs` files in `dist/cjs`:
|
|
16
16
|
- in `.cjs`, adds path-specific imports to non-specific imports
|
|
17
|
-
-
|
|
17
|
+
- strips bare imports that esbuild leaves behind, respecting the `sideEffects` field in package.json
|
|
18
18
|
- outputs `.native.js` and regular `.js` files for all output files, so React Native always loads separate files from web. In the `native` specific files,
|
|
19
19
|
- swc is sued to transform to es5
|
|
20
20
|
- `process.env.TAMAGUI_TARGET` is defined `native` (otherwise `web`)
|
|
@@ -30,7 +30,6 @@ It assumes your package.json looks something like this:
|
|
|
30
30
|
"main": "dist/cjs",
|
|
31
31
|
"module": "dist/esm",
|
|
32
32
|
"type": "module",
|
|
33
|
-
"removeSideEffects": "true",
|
|
34
33
|
"scripts": {
|
|
35
34
|
"build": "tamagui-build",
|
|
36
35
|
"watch": "tamagui-build --watch",
|
|
@@ -69,12 +68,15 @@ It assumes your package.json looks something like this:
|
|
|
69
68
|
### Use
|
|
70
69
|
|
|
71
70
|
- `tamagui-build` - builds `src` folder to `dist` and `types` folders
|
|
71
|
+
- normal builds clear `dist` and `types` first, so stale transformed files don't hang around
|
|
72
|
+
- intermediary `.js` files are removed after `.mjs` / `.cjs` postprocessing, so published output stays lean
|
|
72
73
|
- `tamagui build .` second argument sets baseUrl to tsc
|
|
73
74
|
- `--bundle-modules` - inline node_modules
|
|
74
75
|
- `--declaration-root` - sets tsc flag `--declarationDir ./`
|
|
75
76
|
- `--ignore-base-url` - if not set, tsc is passed `--baseUrl .`
|
|
76
77
|
- `--skip-mjs` - don't output mjs files
|
|
77
78
|
- `--skip-native` - don't output native files
|
|
79
|
+
- `--skip-sourcemaps` - don't output js or declaration sourcemaps
|
|
78
80
|
- `--swap-exports` - swaps `exports.types` from `./src/*.ts` to `./types/*.d.ts` for publishing. if a command is given after `--`, runs it then swaps back. exit code is preserved.
|
|
79
81
|
- `tamagui-build --swap-exports` - build and swap, stays swapped (for manual publish)
|
|
80
82
|
- `tamagui-build --swap-exports -- npm publish` - build, swap, publish, swap back
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MIT
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var index_exports = {};
|
|
16
|
+
__export(index_exports, {
|
|
17
|
+
jsMainFixture: () => jsMainFixture
|
|
18
|
+
});
|
|
19
|
+
module.exports = __toCommonJS(index_exports);
|
|
20
|
+
const jsMainFixture = "ok";
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var index_exports = {};
|
|
24
|
+
__export(index_exports, {
|
|
25
|
+
jsMainFixture: () => jsMainFixture
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var jsMainFixture = "ok";
|
|
29
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","jsMainFixture","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,aAAA,EAAAA,CAAA,KAAAA;AAAA;AAAOC,MAAM,CAAAC,OAAA,GAAAT,YAAgB,CAAAK,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["jsMainFixture"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAO,MAAMA,aAAA,GAAgB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["jsMainFixture"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAO,IAAAA,aAAM,OAAgB","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tamagui-build-test-js-main-package",
|
|
3
|
+
"version": "2.0.0-rc.0-1769885482630",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.mjs",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "node ../../../tamagui-build.js"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@tamagui/build": "workspace:*",
|
|
12
|
+
"typescript": "~5.9.2"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const jsMainFixture = 'ok'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,OAAO,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
$ node ../../../tamagui-build.js
|
|
2
|
-
built tamagui-build-test-simple-tpackage in
|
|
2
|
+
built tamagui-build-test-simple-tpackage in 3496 ms
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
"name": "tamagui-build-test-simple-tpackage",
|
|
3
3
|
"version": "2.0.0-rc.0-1769885482630",
|
|
4
4
|
"main": "dist/cjs",
|
|
5
|
-
"module": "dist/esm
|
|
5
|
+
"module": "dist/esm",
|
|
6
|
+
"module:jsx": "dist/jsx",
|
|
6
7
|
"types": "dist/types/index.d.ts",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"build": "node ../../../tamagui-build.js",
|
|
9
10
|
"build:bundle": "node ../../../tamagui-build.js --bundle",
|
|
10
11
|
"build:skip-mjs": "node ../../../tamagui-build.js --skip-mjs",
|
|
12
|
+
"build:skip-sourcemaps": "node ../../../tamagui-build.js --skip-sourcemaps",
|
|
11
13
|
"build:declaration-root": "node ../../../tamagui-build.js --declaration-root",
|
|
12
14
|
"build:ignore-base-url": "node ../../../tamagui-build.js --ignore-base-url",
|
|
13
15
|
"build:watch": "node ../../../tamagui-build.js --watch",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const nestedHello = 'nested hello'
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
$ node ../../../tamagui-build.js
|
|
2
|
-
built tamagui-build-test-watch-package in
|
|
2
|
+
built tamagui-build-test-watch-package in 2561 ms
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execSync, spawn } from 'node:child_process'
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync, statSync } from 'node:fs'
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync, statSync, readdirSync } from 'node:fs'
|
|
3
3
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
|
4
4
|
import { join } from 'node:path'
|
|
5
5
|
import { readFile } from 'node:fs/promises'
|
|
@@ -15,6 +15,8 @@ const distCjsFilePath = join(distPath, 'cjs', 'index.cjs')
|
|
|
15
15
|
const watchDistCjsFilePath = join(watchDistPath, 'cjs', 'watch.cjs')
|
|
16
16
|
const distEsmFilePath = join(distPath, 'esm', 'index.mjs')
|
|
17
17
|
const distTypesFilePath = join(simplePackagePath, 'types', 'index.d.ts')
|
|
18
|
+
const jsMainPackagePath = join(__dirname, 'fixtures', 'js-main-package')
|
|
19
|
+
const jsMainDistPath = join(jsMainPackagePath, 'dist')
|
|
18
20
|
// console.log({
|
|
19
21
|
// distCjsFilePath,
|
|
20
22
|
// distEsmFilePath,
|
|
@@ -28,6 +30,7 @@ describe('tamagui-build integration test', () => {
|
|
|
28
30
|
beforeAll(() => {
|
|
29
31
|
// Clean up dist directory before starting
|
|
30
32
|
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
33
|
+
execSync('rm -rf dist && rm -rf types', { cwd: jsMainPackagePath })
|
|
31
34
|
})
|
|
32
35
|
|
|
33
36
|
it('should build the package correctly', () => {
|
|
@@ -43,6 +46,10 @@ describe('tamagui-build integration test', () => {
|
|
|
43
46
|
const esmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
44
47
|
expect(cjsOutput).toContain('Hello,')
|
|
45
48
|
expect(esmOutput).toContain('Hello,')
|
|
49
|
+
expect(esmOutput).toContain("./nested/index.mjs")
|
|
50
|
+
expect(existsSync(join(distPath, 'cjs', 'index.cjs'))).toBe(true)
|
|
51
|
+
expect(existsSync(join(distPath, 'esm', 'index.js'))).toBe(true)
|
|
52
|
+
expect(existsSync(join(distPath, 'jsx', 'index.js'))).toBe(true)
|
|
46
53
|
})
|
|
47
54
|
|
|
48
55
|
it('should bundle the package correctly', () => {
|
|
@@ -57,6 +64,9 @@ describe('tamagui-build integration test', () => {
|
|
|
57
64
|
const esmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
58
65
|
expect(cjsOutput).toContain('Hello,')
|
|
59
66
|
expect(esmOutput).toContain('Hello,')
|
|
67
|
+
expect(existsSync(join(distPath, 'cjs', 'index.cjs'))).toBe(true)
|
|
68
|
+
expect(existsSync(join(distPath, 'esm', 'index.js'))).toBe(true)
|
|
69
|
+
expect(existsSync(join(distPath, 'jsx', 'index.js'))).toBe(true)
|
|
60
70
|
})
|
|
61
71
|
|
|
62
72
|
it('should skip mjs files when --skip-mjs is used', () => {
|
|
@@ -66,6 +76,27 @@ describe('tamagui-build integration test', () => {
|
|
|
66
76
|
// Check if the output files exist
|
|
67
77
|
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
68
78
|
expect(existsSync(distEsmFilePath)).toBe(false)
|
|
79
|
+
expect(existsSync(join(distPath, 'cjs', 'index.cjs'))).toBe(true)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('should skip sourcemaps when --skip-sourcemaps is used', () => {
|
|
83
|
+
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
84
|
+
execSync('bun run build:skip-sourcemaps', { cwd: simplePackagePath })
|
|
85
|
+
|
|
86
|
+
expect(existsSync(distCjsFilePath)).toBe(true)
|
|
87
|
+
expect(existsSync(distEsmFilePath)).toBe(true)
|
|
88
|
+
expect(existsSync(distTypesFilePath)).toBe(true)
|
|
89
|
+
expect(existsSync(join(distPath, 'cjs', 'index.cjs.map'))).toBe(false)
|
|
90
|
+
expect(existsSync(join(distPath, 'esm', 'index.mjs.map'))).toBe(false)
|
|
91
|
+
expect(existsSync(join(simplePackagePath, 'types', 'index.d.ts.map'))).toBe(false)
|
|
92
|
+
|
|
93
|
+
const cjsOutput = readFileSync(distCjsFilePath, 'utf-8')
|
|
94
|
+
const esmOutput = readFileSync(distEsmFilePath, 'utf-8')
|
|
95
|
+
const typesOutput = readFileSync(distTypesFilePath, 'utf-8')
|
|
96
|
+
|
|
97
|
+
expect(cjsOutput).not.toContain('sourceMappingURL=')
|
|
98
|
+
expect(esmOutput).not.toContain('sourceMappingURL=')
|
|
99
|
+
expect(typesOutput).not.toContain('sourceMappingURL=')
|
|
69
100
|
})
|
|
70
101
|
|
|
71
102
|
it('should ignore base URL when --ignore-base-url is used', () => {
|
|
@@ -183,12 +214,60 @@ describe('tamagui-build integration test', () => {
|
|
|
183
214
|
expect(esmOutput).not.toMatch(/^\s+$/m) // No lines with only whitespace
|
|
184
215
|
|
|
185
216
|
// Check that the number of lines is reduced
|
|
186
|
-
expect(cjsOutput.split('\n').length).toBeLessThan(32)
|
|
187
|
-
expect(esmOutput.split('\n').length).toBeLessThan(32)
|
|
217
|
+
expect(cjsOutput.split('\n').length).toBeLessThan(originalCjsSize > 0 ? 40 : 32)
|
|
218
|
+
expect(esmOutput.split('\n').length).toBeLessThan(originalEsmSize > 0 ? 40 : 32)
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it('should clean stale outputs before building', () => {
|
|
222
|
+
execSync('bun run build', { cwd: simplePackagePath })
|
|
223
|
+
|
|
224
|
+
const staleFilePath = join(distPath, 'esm', 'stale.mjs')
|
|
225
|
+
const staleTypesPath = join(simplePackagePath, 'types', 'stale.d.ts')
|
|
226
|
+
writeFileSync(staleFilePath, 'stale')
|
|
227
|
+
writeFileSync(staleTypesPath, 'stale')
|
|
228
|
+
|
|
229
|
+
expect(existsSync(staleFilePath)).toBe(true)
|
|
230
|
+
expect(existsSync(staleTypesPath)).toBe(true)
|
|
231
|
+
|
|
232
|
+
execSync('bun run build', { cwd: simplePackagePath })
|
|
233
|
+
|
|
234
|
+
expect(existsSync(staleFilePath)).toBe(false)
|
|
235
|
+
expect(existsSync(staleTypesPath)).toBe(false)
|
|
236
|
+
expect(readdirSync(join(distPath, 'esm'))).not.toContain('stale.mjs')
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
it('should keep only the required js aliases after postprocessing', () => {
|
|
240
|
+
execSync('bun run build', { cwd: simplePackagePath })
|
|
241
|
+
|
|
242
|
+
const distFiles = execSync('find dist -type f | sort', {
|
|
243
|
+
cwd: simplePackagePath,
|
|
244
|
+
encoding: 'utf-8',
|
|
245
|
+
})
|
|
246
|
+
.trim()
|
|
247
|
+
.split('\n')
|
|
248
|
+
.map((file) => file.replace(/^dist\//, ''))
|
|
249
|
+
|
|
250
|
+
expect(distFiles).toContain('cjs/index.cjs')
|
|
251
|
+
expect(distFiles).toContain('esm/index.js')
|
|
252
|
+
expect(distFiles).toContain('esm/index.js.map')
|
|
253
|
+
expect(distFiles).toContain('jsx/index.js')
|
|
254
|
+
expect(distFiles).toContain('jsx/index.js.map')
|
|
255
|
+
expect(distFiles).toContain('cjs/index.cjs')
|
|
256
|
+
expect(distFiles).toContain('esm/index.mjs')
|
|
257
|
+
expect(distFiles).toContain('esm/nested/index.mjs')
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
it('should keep explicit cjs .js mains as final output', () => {
|
|
261
|
+
execSync('bun run build', { cwd: jsMainPackagePath })
|
|
262
|
+
|
|
263
|
+
expect(existsSync(join(jsMainDistPath, 'cjs', 'index.js'))).toBe(true)
|
|
264
|
+
expect(existsSync(join(jsMainDistPath, 'cjs', 'index.mjs'))).toBe(false)
|
|
265
|
+
expect(existsSync(join(jsMainDistPath, 'esm', 'index.mjs'))).toBe(true)
|
|
188
266
|
})
|
|
189
267
|
|
|
190
268
|
afterAll(() => {
|
|
191
269
|
// Clean up dist directory after tests
|
|
192
270
|
execSync('rm -rf dist && rm -rf types', { cwd: simplePackagePath })
|
|
271
|
+
execSync('rm -rf dist && rm -rf types', { cwd: jsMainPackagePath })
|
|
193
272
|
})
|
|
194
273
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/build",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.30",
|
|
4
4
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tamagui-build": "tamagui-build.js",
|
|
@@ -10,27 +10,34 @@
|
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"test": "vitest --run"
|
|
13
|
+
"test": "vitest --run",
|
|
14
|
+
"test:web": "bun run test"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
17
|
"@babel/core": "^7.25.2",
|
|
17
18
|
"@babel/preset-typescript": "^7.26.0",
|
|
18
19
|
"@swc/core": "^1.14.0",
|
|
19
|
-
"@tamagui/babel-plugin-fully-specified": "2.0.0-rc.
|
|
20
|
+
"@tamagui/babel-plugin-fully-specified": "2.0.0-rc.30",
|
|
20
21
|
"@types/fs-extra": "^9.0.13",
|
|
21
|
-
"babel-plugin-react-compiler": "^1.0.0",
|
|
22
22
|
"baseline-browser-mapping": "^2.9.15",
|
|
23
23
|
"chokidar": "^3.5.2",
|
|
24
24
|
"esbuild": "^0.27.2",
|
|
25
|
-
"esbuild-plugin-es5": "^2.1.1",
|
|
26
25
|
"esbuild-register": "^3.6.0",
|
|
27
26
|
"execa": "^5.0.0",
|
|
28
27
|
"fast-glob": "^3.2.11",
|
|
29
28
|
"fs-extra": "^11.2.0",
|
|
30
29
|
"lodash.debounce": "^4.0.8",
|
|
31
|
-
"oxc-transform": "^0.
|
|
30
|
+
"oxc-transform": "^0.112.0",
|
|
32
31
|
"typescript": "~5.9.2"
|
|
33
32
|
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"babel-plugin-react-compiler": ">=1"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"babel-plugin-react-compiler": {
|
|
38
|
+
"optional": true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
34
41
|
"devDependencies": {
|
|
35
42
|
"vitest": "4.0.4"
|
|
36
43
|
}
|
package/pretty-print-errors.js
CHANGED
|
@@ -125,9 +125,42 @@ function printTypescriptCompilationError(err, packageName) {
|
|
|
125
125
|
console.error('')
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Pretty print OXC isolated declaration errors
|
|
130
|
+
* @param {Array<{ severity: string, message: string, labels: Array<{ message: string | null, start: number, end: number }>, helpMessage: string | null, codeframe: string | null }>} errors
|
|
131
|
+
*/
|
|
132
|
+
function printOxcErrors(errors) {
|
|
133
|
+
console.error('\n❌ Type declaration generation errors:\n')
|
|
134
|
+
|
|
135
|
+
errors.forEach((error) => {
|
|
136
|
+
const severity = error.severity === 'Error' ? '❌' : '⚠️ '
|
|
137
|
+
console.error(` ${severity} ${error.message}`)
|
|
138
|
+
|
|
139
|
+
if (error.labels && error.labels.length > 0) {
|
|
140
|
+
error.labels.forEach((label) => {
|
|
141
|
+
console.error(` at ${label.start}-${label.end}`)
|
|
142
|
+
if (label.message) {
|
|
143
|
+
console.error(` ${label.message}`)
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (error.helpMessage) {
|
|
149
|
+
console.error(` help: ${error.helpMessage}`)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (error.codeframe) {
|
|
153
|
+
console.error(`\n${error.codeframe}`)
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
console.error('')
|
|
158
|
+
}
|
|
159
|
+
|
|
128
160
|
module.exports = {
|
|
129
161
|
printTypescriptDiagnostics,
|
|
130
162
|
printEsbuildError,
|
|
131
163
|
printBuildError,
|
|
132
164
|
printTypescriptCompilationError,
|
|
165
|
+
printOxcErrors,
|
|
133
166
|
}
|
package/tamagui-build.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* tamagui-build --watch # watch mode
|
|
10
10
|
* tamagui-build --skip-types # js only
|
|
11
11
|
* tamagui-build --skip-native # skip native builds
|
|
12
|
+
* tamagui-build --skip-sourcemaps # disable js + d.ts sourcemaps
|
|
12
13
|
* tamagui-build clean # remove dist/types/node_modules
|
|
13
14
|
* tamagui-build clean:build # remove dist/types only
|
|
14
15
|
*
|
|
@@ -38,6 +39,7 @@ const {
|
|
|
38
39
|
printEsbuildError,
|
|
39
40
|
printBuildError,
|
|
40
41
|
printTypescriptCompilationError,
|
|
42
|
+
printOxcErrors,
|
|
41
43
|
} = require('./pretty-print-errors')
|
|
42
44
|
|
|
43
45
|
const jsOnly = !!process.env.JS_ONLY
|
|
@@ -45,12 +47,34 @@ const skipJS = !!(process.env.SKIP_JS || false)
|
|
|
45
47
|
|
|
46
48
|
// write file only if contents changed to avoid triggering watchers
|
|
47
49
|
async function writeIfUnchanged(filePath, contents) {
|
|
50
|
+
const isExecutableScript = typeof contents === 'string' && contents.startsWith('#!')
|
|
48
51
|
const existing = await FSE.readFile(filePath, 'utf8').catch(() => null)
|
|
49
|
-
if (existing === contents)
|
|
50
|
-
|
|
52
|
+
if (existing === contents) {
|
|
53
|
+
if (isExecutableScript) {
|
|
54
|
+
await FSE.chmod(filePath, 0o755).catch(() => {})
|
|
55
|
+
}
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
await FSE.outputFile(filePath, contents, {
|
|
59
|
+
encoding: 'utf8',
|
|
60
|
+
mode: isExecutableScript ? 0o755 : 0o666,
|
|
61
|
+
})
|
|
62
|
+
if (isExecutableScript) {
|
|
63
|
+
await FSE.chmod(filePath, 0o755).catch(() => {})
|
|
64
|
+
}
|
|
51
65
|
return true
|
|
52
66
|
}
|
|
53
67
|
|
|
68
|
+
function hasFlag(flag) {
|
|
69
|
+
return process.argv.includes(flag)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getEnvFlag(name) {
|
|
73
|
+
const value = process.env[name]
|
|
74
|
+
if (!value) return false
|
|
75
|
+
return !['0', 'false', 'no', 'off'].includes(String(value).toLowerCase())
|
|
76
|
+
}
|
|
77
|
+
|
|
54
78
|
/**
|
|
55
79
|
* esbuild plugin that runs React Compiler on TS/TSX files before transformation
|
|
56
80
|
*/
|
|
@@ -105,32 +129,34 @@ const reactCompilerPlugin = {
|
|
|
105
129
|
},
|
|
106
130
|
}
|
|
107
131
|
|
|
108
|
-
const shouldSwapExports =
|
|
132
|
+
const shouldSwapExports = hasFlag('--swap-exports')
|
|
109
133
|
|
|
110
134
|
// when swapping exports for publish, we MUST build types (ignore --skip-types)
|
|
111
135
|
const shouldSkipTypes = shouldSwapExports
|
|
112
136
|
? false
|
|
113
|
-
: !!(
|
|
137
|
+
: !!(hasFlag('--skip-types') || process.env.SKIP_TYPES)
|
|
114
138
|
|
|
115
|
-
const shouldSkipNative =
|
|
116
|
-
const shouldSkipMJS =
|
|
139
|
+
const shouldSkipNative = hasFlag('--skip-native')
|
|
140
|
+
const shouldSkipMJS = hasFlag('--skip-mjs')
|
|
141
|
+
const shouldSkipSourceMaps =
|
|
142
|
+
hasFlag('--skip-sourcemaps') || getEnvFlag('TAMAGUI_BUILD_SKIP_SOURCEMAPS')
|
|
117
143
|
// React Compiler is disabled by default - use --react-compiler to enable
|
|
118
144
|
const shouldEnableCompiler = !!(
|
|
119
|
-
|
|
145
|
+
hasFlag('--react-compiler') || process.env.REACT_COMPILER
|
|
120
146
|
)
|
|
121
|
-
const shouldBundleFlag =
|
|
122
|
-
const shouldBundleNodeModules =
|
|
147
|
+
const shouldBundleFlag = hasFlag('--bundle')
|
|
148
|
+
const shouldBundleNodeModules = hasFlag('--bundle-modules')
|
|
123
149
|
const shouldClean = !!process.argv.includes('clean')
|
|
124
150
|
const shouldCleanBuildOnly = !!process.argv.includes('clean:build')
|
|
125
|
-
const shouldWatch =
|
|
151
|
+
const shouldWatch = hasFlag('--watch')
|
|
126
152
|
|
|
127
153
|
// get command after "--" to run with swapped exports
|
|
128
154
|
const dashDashIndex = process.argv.indexOf('--')
|
|
129
155
|
const runCommandAfterSwap =
|
|
130
156
|
dashDashIndex > -1 ? process.argv.slice(dashDashIndex + 1) : null
|
|
131
157
|
|
|
132
|
-
const declarationToRoot =
|
|
133
|
-
const ignoreBaseUrl =
|
|
158
|
+
const declarationToRoot = hasFlag('--declaration-root')
|
|
159
|
+
const ignoreBaseUrl = hasFlag('--ignore-base-url')
|
|
134
160
|
const baseUrlIndex = process.argv.indexOf('--base-url')
|
|
135
161
|
const tsProjectIndex = process.argv.indexOf('--ts-project')
|
|
136
162
|
const exludeIndex = process.argv.indexOf('--exclude')
|
|
@@ -153,7 +179,6 @@ const pkgSource = pkg.source
|
|
|
153
179
|
const pkgModule = pkg.module
|
|
154
180
|
const pkgModuleJSX = pkg['module:jsx']
|
|
155
181
|
const pkgTypes = Boolean(pkg.types || pkg.typings)
|
|
156
|
-
const pkgRemoveSideEffects = pkg.removeSideEffects || false
|
|
157
182
|
|
|
158
183
|
// build config from package.json
|
|
159
184
|
const buildConfig = pkg['tamagui-build'] || {}
|
|
@@ -166,6 +191,20 @@ const bundleExternal = buildConfig.bundleExternal || null
|
|
|
166
191
|
const flatOut = [pkgMain, pkgModule, pkgModuleJSX].filter(Boolean).length === 1
|
|
167
192
|
|
|
168
193
|
const avoidCJS = pkgMain?.endsWith('.js')
|
|
194
|
+
const getJsEntryAliasPath = (entry) => {
|
|
195
|
+
if (!entry) return null
|
|
196
|
+
if (!path.extname(entry)) {
|
|
197
|
+
return path.join(entry, 'index.js').replace(/\\/g, '/')
|
|
198
|
+
}
|
|
199
|
+
if (entry.endsWith('.js')) {
|
|
200
|
+
return entry.replace(/\\/g, '/')
|
|
201
|
+
}
|
|
202
|
+
return null
|
|
203
|
+
}
|
|
204
|
+
const cjsMainAliasPath = getJsEntryAliasPath(pkgMain)
|
|
205
|
+
const esmAliasPaths = [getJsEntryAliasPath(pkgModule), getJsEntryAliasPath(pkgModuleJSX)].filter(
|
|
206
|
+
Boolean
|
|
207
|
+
)
|
|
169
208
|
|
|
170
209
|
const replaceRNWeb = {
|
|
171
210
|
esm: (content) =>
|
|
@@ -236,13 +275,14 @@ if (shouldClean || shouldCleanBuildOnly) {
|
|
|
236
275
|
if (shouldWatch) {
|
|
237
276
|
process.env.IS_WATCHING = true
|
|
238
277
|
process.env.DISABLE_AUTORUN = true
|
|
239
|
-
const rebuild = debounce(build, 100)
|
|
278
|
+
const rebuild = debounce(() => build({ cleanOutput: false }), 100)
|
|
240
279
|
const chokidar = require('chokidar')
|
|
241
280
|
|
|
242
281
|
if (!process.env.SKIP_INITIAL_BUILD) {
|
|
243
282
|
// do one js build but not types
|
|
244
283
|
build({
|
|
245
284
|
skipTypes: true,
|
|
285
|
+
cleanOutput: true,
|
|
246
286
|
})
|
|
247
287
|
}
|
|
248
288
|
|
|
@@ -365,10 +405,18 @@ function swapExportsTypes(pkg, direction) {
|
|
|
365
405
|
return swapped
|
|
366
406
|
}
|
|
367
407
|
|
|
368
|
-
async function build({ skipTypes } = {}) {
|
|
408
|
+
async function build({ skipTypes, cleanOutput = !shouldWatch } = {}) {
|
|
369
409
|
if (process.env.DEBUG) console.info('🔹', pkg.name)
|
|
370
410
|
try {
|
|
371
411
|
const start = Date.now()
|
|
412
|
+
const isSkippingTypesForBuild = Boolean(skipTypes || shouldSkipTypes || !pkgTypes)
|
|
413
|
+
|
|
414
|
+
if (cleanOutput) {
|
|
415
|
+
await Promise.allSettled([
|
|
416
|
+
FSE.remove('dist'),
|
|
417
|
+
isSkippingTypesForBuild ? null : FSE.remove('types'),
|
|
418
|
+
])
|
|
419
|
+
}
|
|
372
420
|
|
|
373
421
|
const allFiles = (await fastGlob(['src/**/*.(m)?[jt]s(x)?', 'src/**/*.css'])).filter(
|
|
374
422
|
(x) => !x.includes('.d.ts') && (exclude ? !x.match(exclude) : true)
|
|
@@ -441,29 +489,48 @@ async function buildTsc(allFiles) {
|
|
|
441
489
|
const compilerOptions = createCompilerOptions(config.options, targetDir)
|
|
442
490
|
|
|
443
491
|
if (config.options.isolatedDeclarations) {
|
|
444
|
-
const oxc =
|
|
492
|
+
const oxc = await import('oxc-transform')
|
|
445
493
|
|
|
446
|
-
await Promise.all(
|
|
494
|
+
const results = await Promise.all(
|
|
447
495
|
allFiles.map(async (file) => {
|
|
448
496
|
const source = await FSE.readFile(file, 'utf-8')
|
|
449
|
-
const { code, map } = oxc.isolatedDeclaration(file, source, {
|
|
450
|
-
sourcemap:
|
|
497
|
+
const { code, map, errors } = await oxc.isolatedDeclaration(file, source, {
|
|
498
|
+
sourcemap: !shouldSkipSourceMaps,
|
|
451
499
|
})
|
|
452
500
|
|
|
501
|
+
if (errors && errors.length > 0) {
|
|
502
|
+
return errors
|
|
503
|
+
}
|
|
504
|
+
|
|
453
505
|
const dtsPath = path
|
|
454
506
|
.join(`types`, ...file.split('/').slice(1))
|
|
455
507
|
.replace(/\.tsx?$/, '.d.ts')
|
|
456
508
|
const mapPath = `${dtsPath}.map`
|
|
457
509
|
|
|
458
|
-
const output =
|
|
510
|
+
const output = shouldSkipSourceMaps
|
|
511
|
+
? code
|
|
512
|
+
: `${code}\n//# sourceMappingURL=${path.basename(mapPath)}`
|
|
459
513
|
await FSE.ensureDir(dirname(dtsPath))
|
|
460
|
-
await
|
|
461
|
-
|
|
462
|
-
writeIfUnchanged(mapPath, JSON.stringify(map, null, 2))
|
|
463
|
-
|
|
514
|
+
await writeIfUnchanged(dtsPath, output)
|
|
515
|
+
if (!shouldSkipSourceMaps && map) {
|
|
516
|
+
await writeIfUnchanged(mapPath, JSON.stringify(map, null, 2))
|
|
517
|
+
} else {
|
|
518
|
+
await FSE.remove(mapPath)
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
return []
|
|
464
522
|
})
|
|
465
523
|
)
|
|
466
524
|
|
|
525
|
+
const allErrors = results.flat()
|
|
526
|
+
|
|
527
|
+
if (allErrors.length > 0) {
|
|
528
|
+
printOxcErrors(allErrors)
|
|
529
|
+
if (!shouldWatch) {
|
|
530
|
+
process.exit(1)
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
467
534
|
return
|
|
468
535
|
}
|
|
469
536
|
|
|
@@ -540,7 +607,7 @@ function createCompilerOptions(baseOptions, targetDir) {
|
|
|
540
607
|
...baseOptions,
|
|
541
608
|
declaration: true,
|
|
542
609
|
emitDeclarationOnly: true,
|
|
543
|
-
declarationMap:
|
|
610
|
+
declarationMap: !shouldSkipSourceMaps,
|
|
544
611
|
outDir: targetDir,
|
|
545
612
|
rootDir: 'src',
|
|
546
613
|
incremental: true,
|
|
@@ -701,6 +768,8 @@ async function buildJs(allFiles) {
|
|
|
701
768
|
platform: 'web',
|
|
702
769
|
bundle: shouldBundleFlag,
|
|
703
770
|
specifyCJS: !avoidCJS,
|
|
771
|
+
keepJsOutput: avoidCJS,
|
|
772
|
+
preserveJsPaths: [],
|
|
704
773
|
})
|
|
705
774
|
: null,
|
|
706
775
|
|
|
@@ -716,6 +785,7 @@ async function buildJs(allFiles) {
|
|
|
716
785
|
? esbuildWriteIfChanged(esmConfig, {
|
|
717
786
|
platform: 'web',
|
|
718
787
|
bundle: shouldBundleFlag,
|
|
788
|
+
preserveJsPaths: esmAliasPaths,
|
|
719
789
|
})
|
|
720
790
|
: null,
|
|
721
791
|
|
|
@@ -743,6 +813,7 @@ async function buildJs(allFiles) {
|
|
|
743
813
|
},
|
|
744
814
|
{
|
|
745
815
|
platform: 'web',
|
|
816
|
+
preserveJsPaths: esmAliasPaths,
|
|
746
817
|
}
|
|
747
818
|
)
|
|
748
819
|
: null,
|
|
@@ -784,9 +855,11 @@ async function buildJs(allFiles) {
|
|
|
784
855
|
async function esbuildWriteIfChanged(
|
|
785
856
|
/** @type { import('esbuild').BuildOptions } */
|
|
786
857
|
opts,
|
|
787
|
-
{ platform, env, specifyCJS } = {
|
|
858
|
+
{ platform, env, specifyCJS, keepJsOutput, preserveJsPaths } = {
|
|
788
859
|
platform: '',
|
|
789
860
|
specifyCJS: false,
|
|
861
|
+
keepJsOutput: false,
|
|
862
|
+
preserveJsPaths: [],
|
|
790
863
|
env: '',
|
|
791
864
|
}
|
|
792
865
|
) {
|
|
@@ -795,6 +868,10 @@ async function esbuildWriteIfChanged(
|
|
|
795
868
|
}
|
|
796
869
|
|
|
797
870
|
const isESM = opts.target === 'esm' || opts.target === 'esnext'
|
|
871
|
+
const preserveJsPathSet = new Set((preserveJsPaths || []).filter(Boolean))
|
|
872
|
+
const preserveJsPathAbsoluteSet = new Set(
|
|
873
|
+
[...preserveJsPathSet].map((preserveJsPath) => path.resolve(preserveJsPath))
|
|
874
|
+
)
|
|
798
875
|
|
|
799
876
|
const buildSettings = (() => {
|
|
800
877
|
// compat with jsx and hermes back a few versions generally:
|
|
@@ -852,7 +929,7 @@ async function esbuildWriteIfChanged(
|
|
|
852
929
|
color: true,
|
|
853
930
|
allowOverwrite: true,
|
|
854
931
|
keepNames: false,
|
|
855
|
-
sourcemap:
|
|
932
|
+
sourcemap: !shouldSkipSourceMaps,
|
|
856
933
|
sourcesContent: false,
|
|
857
934
|
logLevel: 'error',
|
|
858
935
|
...(platform === 'native' && nativeEsbuildSettings),
|
|
@@ -962,23 +1039,35 @@ async function esbuildWriteIfChanged(
|
|
|
962
1039
|
}
|
|
963
1040
|
}
|
|
964
1041
|
|
|
965
|
-
if (
|
|
966
|
-
const
|
|
1042
|
+
if (isESM && pkg.sideEffects !== true && pkg.sideEffects !== undefined) {
|
|
1043
|
+
const sideEffects = pkg.sideEffects
|
|
1044
|
+
// sideEffects: false means nothing has side effects, strip all bare imports
|
|
1045
|
+
// sideEffects: ["*.css", ...] means only matching files have side effects
|
|
1046
|
+
const picomatch = require('picomatch')
|
|
1047
|
+
const matchers = sideEffects === false
|
|
1048
|
+
? null // strip everything
|
|
1049
|
+
: (Array.isArray(sideEffects) ? sideEffects : []).map((p) => picomatch(p))
|
|
967
1050
|
|
|
968
1051
|
const result = []
|
|
969
1052
|
const lines = contents.split('\n')
|
|
970
1053
|
for (const line of lines) {
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
) {
|
|
1054
|
+
// only process bare imports: import "...";
|
|
1055
|
+
const match = line.match(/^import\s+["']([^"']+)["'];?$/)
|
|
1056
|
+
if (!match) {
|
|
975
1057
|
result.push(line)
|
|
976
1058
|
continue
|
|
977
1059
|
}
|
|
978
|
-
|
|
1060
|
+
const specifier = match[1].replace(/^\.\//, '')
|
|
1061
|
+
// sideEffects: false → strip all bare imports
|
|
1062
|
+
if (matchers === null) {
|
|
1063
|
+
result.push('')
|
|
1064
|
+
continue
|
|
1065
|
+
}
|
|
1066
|
+
// sideEffects: [...] → keep if specifier matches any pattern
|
|
1067
|
+
const hasSideEffect = matchers.some((m) => m(specifier))
|
|
1068
|
+
result.push(hasSideEffect ? line : '')
|
|
979
1069
|
}
|
|
980
1070
|
|
|
981
|
-
// match whitespace to preserve sourcemaps
|
|
982
1071
|
contents = result.join('\n')
|
|
983
1072
|
}
|
|
984
1073
|
|
|
@@ -1018,7 +1107,7 @@ async function esbuildWriteIfChanged(
|
|
|
1018
1107
|
: transform(contents, {
|
|
1019
1108
|
filename: path,
|
|
1020
1109
|
configFile: false,
|
|
1021
|
-
sourceMap:
|
|
1110
|
+
sourceMap: !shouldSkipSourceMaps,
|
|
1022
1111
|
plugins: [
|
|
1023
1112
|
[
|
|
1024
1113
|
require.resolve('@tamagui/babel-plugin-fully-specified/commonjs'),
|
|
@@ -1029,11 +1118,28 @@ async function esbuildWriteIfChanged(
|
|
|
1029
1118
|
].filter(Boolean),
|
|
1030
1119
|
})
|
|
1031
1120
|
|
|
1032
|
-
|
|
1121
|
+
const shouldPreserveJsAlias =
|
|
1122
|
+
preserveJsPathSet.has(path) || preserveJsPathAbsoluteSet.has(path)
|
|
1123
|
+
|
|
1124
|
+
if (!shouldPreserveJsAlias) {
|
|
1125
|
+
cleanupNonCjsFiles.push(path)
|
|
1126
|
+
cleanupNonCjsFiles.push(path + '.map')
|
|
1127
|
+
}
|
|
1033
1128
|
|
|
1034
1129
|
await flush(path.replace(/\.js$/, '.cjs'), result.code)
|
|
1130
|
+
|
|
1131
|
+
if (shouldPreserveJsAlias) {
|
|
1132
|
+
await flush(path, result.code)
|
|
1133
|
+
}
|
|
1035
1134
|
})
|
|
1036
1135
|
)
|
|
1136
|
+
if (cleanupNonCjsFiles.length) {
|
|
1137
|
+
await Promise.all(cleanupNonCjsFiles.map(async (file) => FSE.remove(file)))
|
|
1138
|
+
}
|
|
1139
|
+
return
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
if (keepJsOutput) {
|
|
1037
1143
|
return
|
|
1038
1144
|
}
|
|
1039
1145
|
|
|
@@ -1060,7 +1166,7 @@ async function esbuildWriteIfChanged(
|
|
|
1060
1166
|
: transform(contents, {
|
|
1061
1167
|
filename: newOutPath,
|
|
1062
1168
|
configFile: false,
|
|
1063
|
-
sourceMap:
|
|
1169
|
+
sourceMap: !shouldSkipSourceMaps,
|
|
1064
1170
|
plugins: [
|
|
1065
1171
|
[
|
|
1066
1172
|
isESM
|
|
@@ -1074,7 +1180,10 @@ async function esbuildWriteIfChanged(
|
|
|
1074
1180
|
].filter(Boolean),
|
|
1075
1181
|
})
|
|
1076
1182
|
|
|
1077
|
-
|
|
1183
|
+
const shouldPreserveJsAlias =
|
|
1184
|
+
preserveJsPathSet.has(path) || preserveJsPathAbsoluteSet.has(path)
|
|
1185
|
+
|
|
1186
|
+
if (!path.includes('.native.') && !shouldPreserveJsAlias) {
|
|
1078
1187
|
cleanupNonMjsFiles.push(path)
|
|
1079
1188
|
cleanupNonMjsFiles.push(path + '.map')
|
|
1080
1189
|
}
|
|
@@ -1083,25 +1192,39 @@ async function esbuildWriteIfChanged(
|
|
|
1083
1192
|
await flush(
|
|
1084
1193
|
newOutPath,
|
|
1085
1194
|
result.code +
|
|
1086
|
-
(result.map
|
|
1195
|
+
(result.map && !shouldSkipSourceMaps
|
|
1196
|
+
? `\n//# sourceMappingURL=${basename(newOutPath)}.map\n`
|
|
1197
|
+
: '')
|
|
1087
1198
|
)
|
|
1088
|
-
if (result.map) {
|
|
1199
|
+
if (result.map && !shouldSkipSourceMaps) {
|
|
1089
1200
|
await flush(newOutPath + '.map', JSON.stringify(result.map))
|
|
1201
|
+
} else {
|
|
1202
|
+
await FSE.remove(newOutPath + '.map')
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
if (shouldPreserveJsAlias) {
|
|
1206
|
+
await flush(
|
|
1207
|
+
path,
|
|
1208
|
+
result.code +
|
|
1209
|
+
(result.map && !shouldSkipSourceMaps
|
|
1210
|
+
? `\n//# sourceMappingURL=${basename(path)}.map\n`
|
|
1211
|
+
: '')
|
|
1212
|
+
)
|
|
1213
|
+
if (result.map && !shouldSkipSourceMaps) {
|
|
1214
|
+
await flush(path + '.map', JSON.stringify(result.map))
|
|
1215
|
+
} else {
|
|
1216
|
+
await FSE.remove(path + '.map')
|
|
1217
|
+
}
|
|
1090
1218
|
}
|
|
1091
1219
|
})
|
|
1092
1220
|
)
|
|
1093
1221
|
|
|
1094
|
-
//
|
|
1095
|
-
if (
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
[...cleanupNonMjsFiles, ...cleanupNonCjsFiles].map(async (file) => {
|
|
1102
|
-
await FSE.remove(file)
|
|
1103
|
-
})
|
|
1104
|
-
)
|
|
1105
|
-
}
|
|
1222
|
+
// remove intermediary .js files once the final .mjs/.cjs outputs exist
|
|
1223
|
+
if (cleanupNonMjsFiles.length || cleanupNonCjsFiles.length) {
|
|
1224
|
+
await Promise.all(
|
|
1225
|
+
[...cleanupNonMjsFiles, ...cleanupNonCjsFiles].map(async (file) => {
|
|
1226
|
+
await FSE.remove(file)
|
|
1227
|
+
})
|
|
1228
|
+
)
|
|
1106
1229
|
}
|
|
1107
1230
|
}
|