@octane-xplat/bamboo 0.18.0 → 0.20.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 +2 -95
- package/dist/platform-output.js +1 -1
- package/dist/vite.js +2 -2
- package/package.json +65 -63
- package/src/build-environments.ts +62 -56
- package/src/config.ts +114 -113
- package/src/platform-output.ts +218 -198
- package/src/vite.ts +114 -110
- package/LICENSE +0 -21
package/src/vite.ts
CHANGED
|
@@ -4,25 +4,26 @@ import { buildEnvironments as adaptBuildEnvironments } from './build-environment
|
|
|
4
4
|
import { platformOutput } from './platform-output.ts'
|
|
5
5
|
|
|
6
6
|
function runBeforeNativeCss(plugin: Plugin | undefined, anchor: string) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
const hook = plugin?.generateBundle
|
|
8
|
+
|
|
9
|
+
if (plugin && typeof hook === 'function') {
|
|
10
|
+
plugin.generateBundle = { order: 'pre', handler: hook }
|
|
11
|
+
} else if (hook && typeof hook === 'object' && typeof hook.handler === 'function') {
|
|
12
|
+
hook.order = 'pre'
|
|
13
|
+
} else {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`@octane-xplat/bamboo: native CSS adaptation requires ${anchor} with a generateBundle handler`,
|
|
16
|
+
)
|
|
17
|
+
}
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export interface XplatBambooOptions extends BambooVitePluginOptions {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/** Native CSS delivery — NativeScript's generateBundle serializer and the
|
|
22
|
+
* desktop `xplatInlineStylesheets` plugin both consume the finalized assets
|
|
23
|
+
* after this 'pre' finalizer. */
|
|
24
|
+
native?: boolean
|
|
25
|
+
/** All environments the custom Vite builder will run, including real SSR targets. */
|
|
26
|
+
buildEnvironments?: readonly string[]
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
/**
|
|
@@ -32,99 +33,102 @@ export interface XplatBambooOptions extends BambooVitePluginOptions {
|
|
|
32
33
|
* Vite's app root, as it does in the shared harness.
|
|
33
34
|
*/
|
|
34
35
|
export function xplatBamboo({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
native = false,
|
|
37
|
+
buildEnvironments,
|
|
38
|
+
...options
|
|
38
39
|
}: XplatBambooOptions = {}) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
40
|
+
const plugins = bamboocss(options)
|
|
41
|
+
|
|
42
|
+
if (buildEnvironments) {
|
|
43
|
+
adaptBuildEnvironments(plugins, buildEnvironments)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (native) {
|
|
47
|
+
// Let Bamboo prune and validate the emitted asset before NativeScript's
|
|
48
|
+
// main-entry hook serializes it into the native bootstrap and removes it.
|
|
49
|
+
const cssPlugin = plugins.find((plugin) => plugin.name === 'bamboocss:css')
|
|
50
|
+
|
|
51
|
+
runBeforeNativeCss(cssPlugin, 'bamboocss:css')
|
|
52
|
+
|
|
53
|
+
let isBuild = false
|
|
54
|
+
|
|
55
|
+
plugins.push({
|
|
56
|
+
name: 'xplat-bamboo:nativescript-entry-graph',
|
|
57
|
+
enforce: 'post',
|
|
58
|
+
configResolved(config) {
|
|
59
|
+
isBuild = config.command === 'build'
|
|
60
|
+
},
|
|
61
|
+
buildEnd(error) {
|
|
62
|
+
if (!isBuild || error) {
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Inspect the graph, including cached modules in watch builds. A
|
|
67
|
+
// custom entry that already imports the sheet needs no injection.
|
|
68
|
+
if (![...this.getModuleIds()].some((id) => id.split('?')[0] === '\0virtual:bamboo.css')) {
|
|
69
|
+
this.error(
|
|
70
|
+
'@octane-xplat/bamboo: native entry graph is missing virtual:bamboo.css; expected virtual:entry-with-polyfills or an explicit stylesheet import',
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
transform(code, id) {
|
|
75
|
+
// @nativescript/vite builds from a generated entry
|
|
76
|
+
// (`virtual:entry-with-polyfills`). Under HMR that entry boots
|
|
77
|
+
// the app over HTTP instead of statically importing the app's
|
|
78
|
+
// main module, so `import 'virtual:bamboo.css'` there never
|
|
79
|
+
// enters the bundle's module graph — while class values still
|
|
80
|
+
// compile, tripping bamboocss's entry-graph check at buildEnd.
|
|
81
|
+
// Import the stylesheet from the generated entry itself so it
|
|
82
|
+
// is in the graph in every mode; the emitted asset then flows
|
|
83
|
+
// through the same generateBundle path as every other .css.
|
|
84
|
+
if (id !== '\0virtual:entry-with-polyfills' || code.includes('virtual:bamboo.css')) {
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return { code: `${code}\nimport 'virtual:bamboo.css';\n`, map: null }
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
plugins.push({
|
|
93
|
+
name: 'xplat-bamboo:nativescript-output',
|
|
94
|
+
enforce: 'post',
|
|
95
|
+
options: {
|
|
96
|
+
order: 'post',
|
|
97
|
+
handler(inputOptions) {
|
|
98
|
+
const options = inputOptions as typeof inputOptions & {
|
|
99
|
+
output?: { plugins?: Plugin[] } | Array<{ plugins?: Plugin[] }>
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const outputs = Array.isArray(options.output)
|
|
103
|
+
? options.output
|
|
104
|
+
: options.output
|
|
105
|
+
? [options.output]
|
|
106
|
+
: []
|
|
107
|
+
|
|
108
|
+
// Upstream installs one finalizer per configured output. With no
|
|
109
|
+
// output configured its options hook deliberately installs none.
|
|
110
|
+
for (const output of outputs) {
|
|
111
|
+
const finalizers = (output.plugins ?? [])
|
|
112
|
+
.flat(Infinity)
|
|
113
|
+
.filter((plugin): plugin is Plugin =>
|
|
114
|
+
Boolean(plugin && plugin.name?.startsWith('bamboocss:output-finalizer:')),
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
if (!finalizers.length) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
'@octane-xplat/bamboo: native CSS adaptation requires a bamboocss:output-finalizer:* plugin for each configured output',
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (const finalizer of finalizers) {
|
|
124
|
+
runBeforeNativeCss(finalizer, finalizer.name)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
plugins.push(platformOutput())
|
|
133
|
+
return plugins
|
|
130
134
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Alec Larson
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|