@gjsify/rolldown-plugin-gjsify 0.41.0 → 0.43.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/lib/app/browser.d.ts +2 -0
- package/lib/app/browser.js +4 -2
- package/lib/app/gjs.d.ts +10 -0
- package/lib/app/gjs.js +17 -4
- package/lib/app/nativescript.d.ts +2 -0
- package/lib/app/nativescript.js +4 -2
- package/lib/app/node.d.ts +2 -0
- package/lib/app/node.js +4 -2
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/library/lib.d.ts +2 -0
- package/lib/library/lib.js +12 -1
- package/lib/plugin.d.ts +25 -0
- package/lib/plugin.js +1 -0
- package/lib/plugins/gi-runtime-paths.d.ts +27 -5
- package/lib/plugins/gi-runtime-paths.js +74 -27
- package/lib/plugins/intl-segmenter-banner.d.ts +1 -0
- package/lib/plugins/intl-segmenter-banner.js +42 -0
- package/lib/plugins/process-stub.d.ts +7 -0
- package/lib/plugins/process-stub.js +5 -1
- package/lib/plugins/rewrite-node-modules-paths.d.ts +35 -0
- package/lib/plugins/rewrite-node-modules-paths.js +57 -5
- package/lib/plugins/unresolved-workspace-import.d.ts +48 -2
- package/lib/plugins/unresolved-workspace-import.js +71 -7
- package/lib/types/plugin-options.d.ts +12 -0
- package/lib/utils/detect-free-globals.js +29 -7
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/inline-static-reads.d.ts +0 -7
- package/lib/utils/inline-static-reads.js +79 -16
- package/lib/utils/jsx-survival.d.ts +31 -0
- package/lib/utils/jsx-survival.js +102 -0
- package/package.json +10 -8
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Raw JSX surviving into an emitted bundle — the syntax-level oracle, and why it is a
|
|
2
|
+
// syntax check rather than a pattern match.
|
|
3
|
+
//
|
|
4
|
+
// `jsx: "preserve"` is the setting `babel-preset-solid` and the Vue SFC compiler need:
|
|
5
|
+
// it tells oxc to leave JSX alone so the framework's own compiler can handle it. When
|
|
6
|
+
// that compiler is absent, raw JSX travels all the way into the `.gjs.mjs` and NOTHING
|
|
7
|
+
// between `gjsify build` and the artifact notices — rolldown emits it, the build exits
|
|
8
|
+
// 0, and GJS refuses the file at LOAD, before one line runs. MEASURED on a two-line
|
|
9
|
+
// `.tsx` built `--app gjs --globals none`: exit 0, `r=<box title="hi"/>` in the bundle,
|
|
10
|
+
// and `SyntaxError: expected expression, got '<'` under `gjs -m`.
|
|
11
|
+
//
|
|
12
|
+
// A pattern match is the wrong oracle in both directions: `<div` hits a string inside a
|
|
13
|
+
// test name, and misses `<Foo.Bar>`, `<>` and every tag the pattern did not think of.
|
|
14
|
+
// The right question is the one GJS asks — "does this parse as an ES module?" — so this
|
|
15
|
+
// asks acorn, the same parser the `--globals auto` detector already runs over bundled
|
|
16
|
+
// output.
|
|
17
|
+
//
|
|
18
|
+
// A parse failure ALONE is not attributed to JSX: acorn trails SpiderMonkey on new
|
|
19
|
+
// syntax, and blaming JSX for something else would send the reader after a setting that
|
|
20
|
+
// is already right. The attribution is the FAILURE POSITION — a `<` followed by an
|
|
21
|
+
// identifier start, `>` (fragment) or `/` (closing tag). That is where acorn stops on
|
|
22
|
+
// every JSX shape measured: `<box …/>`, `<box>hi</box>`, `<>…</>`, `<Foo.Bar x={1}>`,
|
|
23
|
+
// JSX as a call argument, and JSX in a multi-declarator `const`.
|
|
24
|
+
import * as acorn from 'acorn';
|
|
25
|
+
/**
|
|
26
|
+
* What may follow the `<` for the failure to read as JSX rather than as a broken
|
|
27
|
+
* comparison: a tag name, a fragment (`<>`) or a closing tag (`</`).
|
|
28
|
+
*/
|
|
29
|
+
const JSX_AFTER_ANGLE_RE = /^[A-Za-z_$>/]/;
|
|
30
|
+
/** Characters of context kept around the failure position. */
|
|
31
|
+
const EXCERPT_RADIUS = 60;
|
|
32
|
+
function excerptAt(code, pos) {
|
|
33
|
+
const from = Math.max(0, pos - EXCERPT_RADIUS);
|
|
34
|
+
const to = Math.min(code.length, pos + EXCERPT_RADIUS);
|
|
35
|
+
// Newlines and tabs would break the one-line-per-fact shape of the message.
|
|
36
|
+
const text = code.slice(from, to).replace(/[\r\n\t]+/g, ' ');
|
|
37
|
+
return `${from > 0 ? '…' : ''}${text}${to < code.length ? '…' : ''}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Does `err` — a failure from parsing `code` — say that raw JSX survived? Returns the
|
|
41
|
+
* location when the position attributes it to JSX, `null` when it does not.
|
|
42
|
+
*
|
|
43
|
+
* Split from {@link locateSurvivingJsx} so a caller that ALREADY parsed (and threw) can
|
|
44
|
+
* attribute its own failure without parsing a second time.
|
|
45
|
+
*/
|
|
46
|
+
export function classifyJsxParseFailure(code, err) {
|
|
47
|
+
const pos = err.pos;
|
|
48
|
+
const loc = err.loc;
|
|
49
|
+
if (typeof pos !== 'number')
|
|
50
|
+
return null;
|
|
51
|
+
if (typeof loc?.line !== 'number' || typeof loc.column !== 'number')
|
|
52
|
+
return null;
|
|
53
|
+
if (code[pos] !== '<')
|
|
54
|
+
return null;
|
|
55
|
+
if (!JSX_AFTER_ANGLE_RE.test(code.slice(pos + 1, pos + 2)))
|
|
56
|
+
return null;
|
|
57
|
+
return { line: loc.line, column: loc.column, excerpt: excerptAt(code, pos) };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parse `code` as an ES module and report surviving JSX. `null` means either "parses
|
|
61
|
+
* fine" or "fails for a reason that is not JSX" — the two cases this must not conflate,
|
|
62
|
+
* because only the first is a healthy bundle and only the second is acorn's problem
|
|
63
|
+
* rather than the build's.
|
|
64
|
+
*/
|
|
65
|
+
export function locateSurvivingJsx(code) {
|
|
66
|
+
try {
|
|
67
|
+
acorn.parse(code, {
|
|
68
|
+
ecmaVersion: 'latest',
|
|
69
|
+
sourceType: 'module',
|
|
70
|
+
// Any project bundling its own CLI gets a shebang hoisted to byte 0.
|
|
71
|
+
allowHashBang: true,
|
|
72
|
+
});
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
return classifyJsxParseFailure(code, err);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The actionable message: what the artifact does, what the runtime will do with it, and
|
|
81
|
+
* the two settings that fix it. Shared by the post-bundle artifact gate and the
|
|
82
|
+
* `--globals auto` analysis pass, which hits the same source with a bare
|
|
83
|
+
* "Unexpected token (3:11)" naming neither JSX nor a setting.
|
|
84
|
+
*/
|
|
85
|
+
export function formatSurvivingJsx(found, label) {
|
|
86
|
+
return [
|
|
87
|
+
`gjsify build: ${label} still contains raw JSX at ${found.line}:${found.column} — it is not valid ` +
|
|
88
|
+
'JavaScript, so GJS aborts at load with "SyntaxError: expected expression, got \'<\'" before one ' +
|
|
89
|
+
'line runs.',
|
|
90
|
+
` ${found.excerpt}`,
|
|
91
|
+
'',
|
|
92
|
+
'JSX reaches an artifact only when the transform was told to PRESERVE it (`jsx: "preserve"` in ' +
|
|
93
|
+
'`gjsify.bundler.transform.jsx` or in tsconfig `compilerOptions.jsx`) and nothing compiled it ' +
|
|
94
|
+
'afterwards. Either:',
|
|
95
|
+
' - register the framework compiler that consumes preserved JSX (`babel-preset-solid` for Solid, the ' +
|
|
96
|
+
'Vue SFC compiler) under `gjsify.bundler.plugins`, or',
|
|
97
|
+
' - drop `preserve` and give the automatic runtime an import source that resolves AND runs: ' +
|
|
98
|
+
'`bundler.transform.jsx: { "importSource": "<pkg exporting ./jsx-runtime>" }`, or tsconfig ' +
|
|
99
|
+
'`"jsx": "react-jsx"` + `"jsxImportSource"`. Not `@gjsify/gtk-host` — its `/jsx-runtime` is a ' +
|
|
100
|
+
'TYPE surface and throws when called.',
|
|
101
|
+
].join('\n');
|
|
102
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/rolldown-plugin-gjsify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "Rolldown / Rollup / Vite plugin orchestrator for GJS, Node, and Browser targets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"repository": {
|
|
41
41
|
"type": "git",
|
|
42
|
-
"url": "git+https://github.com/gjsify/gjsify.git"
|
|
42
|
+
"url": "git+https://github.com/gjsify/gjsify.git",
|
|
43
|
+
"directory": "packages/infra/rolldown-plugin-gjsify"
|
|
43
44
|
},
|
|
44
45
|
"bugs": {
|
|
45
46
|
"url": "https://github.com/gjsify/gjsify/issues"
|
|
@@ -55,20 +56,21 @@
|
|
|
55
56
|
],
|
|
56
57
|
"license": "MIT",
|
|
57
58
|
"dependencies": {
|
|
58
|
-
"@gjsify/console": "^0.
|
|
59
|
-
"@gjsify/resolve-npm": "^0.
|
|
60
|
-
"@gjsify/rolldown-plugin-deepkit": "^0.
|
|
61
|
-
"@gjsify/rolldown-plugin-pnp": "^0.
|
|
62
|
-
"@gjsify/vite-plugin-blueprint": "^0.
|
|
59
|
+
"@gjsify/console": "^0.43.0",
|
|
60
|
+
"@gjsify/resolve-npm": "^0.43.0",
|
|
61
|
+
"@gjsify/rolldown-plugin-deepkit": "^0.43.0",
|
|
62
|
+
"@gjsify/rolldown-plugin-pnp": "^0.43.0",
|
|
63
|
+
"@gjsify/vite-plugin-blueprint": "^0.43.0",
|
|
63
64
|
"@rollup/pluginutils": "^5.4.0",
|
|
64
65
|
"acorn": "^8.17.0",
|
|
66
|
+
"acorn-typescript": "^1.4.13",
|
|
65
67
|
"acorn-walk": "^8.3.5",
|
|
66
68
|
"fast-glob": "^3.3.3",
|
|
67
69
|
"lightningcss": "^1.32.0",
|
|
68
70
|
"sass": "^1.101.0"
|
|
69
71
|
},
|
|
70
72
|
"peerDependencies": {
|
|
71
|
-
"@gjsify/lightningcss-native": "^0.
|
|
73
|
+
"@gjsify/lightningcss-native": "^0.43.0",
|
|
72
74
|
"rolldown": "^1.1.4"
|
|
73
75
|
},
|
|
74
76
|
"peerDependenciesMeta": {
|