@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/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
- const hook = plugin?.generateBundle
8
- if (plugin && typeof hook === 'function') {
9
- plugin.generateBundle = { order: 'pre', handler: hook }
10
- } else if (hook && typeof hook === 'object' && typeof hook.handler === 'function') {
11
- hook.order = 'pre'
12
- } else {
13
- throw new Error(
14
- `@octane-xplat/bamboo: native CSS adaptation requires ${anchor} with a generateBundle handler`,
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
- /** Native CSS delivery — NativeScript's generateBundle serializer and the
21
- * desktop `xplatInlineStylesheets` plugin both consume the finalized assets
22
- * after this 'pre' finalizer. */
23
- native?: boolean
24
- /** All environments the custom Vite builder will run, including real SSR targets. */
25
- buildEnvironments?: readonly string[]
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
- native = false,
36
- buildEnvironments,
37
- ...options
36
+ native = false,
37
+ buildEnvironments,
38
+ ...options
38
39
  }: XplatBambooOptions = {}) {
39
- const plugins = bamboocss(options)
40
- if (buildEnvironments) {
41
- adaptBuildEnvironments(plugins, buildEnvironments)
42
- }
43
-
44
- if (native) {
45
- // Let Bamboo prune and validate the emitted asset before NativeScript's
46
- // main-entry hook serializes it into the native bootstrap and removes it.
47
- const cssPlugin = plugins.find((plugin) => plugin.name === 'bamboocss:css')
48
- runBeforeNativeCss(cssPlugin, 'bamboocss:css')
49
-
50
- let isBuild = false
51
- plugins.push({
52
- name: 'xplat-bamboo:nativescript-entry-graph',
53
- enforce: 'post',
54
- configResolved(config) {
55
- isBuild = config.command === 'build'
56
- },
57
- buildEnd(error) {
58
- if (!isBuild || error) {
59
- return
60
- }
61
-
62
- // Inspect the graph, including cached modules in watch builds. A
63
- // custom entry that already imports the sheet needs no injection.
64
- if (![...this.getModuleIds()].some((id) => id.split('?')[0] === '\0virtual:bamboo.css')) {
65
- this.error(
66
- '@octane-xplat/bamboo: native entry graph is missing virtual:bamboo.css; expected virtual:entry-with-polyfills or an explicit stylesheet import',
67
- )
68
- }
69
- },
70
- transform(code, id) {
71
- // @nativescript/vite builds from a generated entry
72
- // (`virtual:entry-with-polyfills`). Under HMR that entry boots
73
- // the app over HTTP instead of statically importing the app's
74
- // main module, so `import 'virtual:bamboo.css'` there never
75
- // enters the bundle's module graph — while class values still
76
- // compile, tripping bamboocss's entry-graph check at buildEnd.
77
- // Import the stylesheet from the generated entry itself so it
78
- // is in the graph in every mode; the emitted asset then flows
79
- // through the same generateBundle path as every other .css.
80
- if (id !== '\0virtual:entry-with-polyfills' || code.includes('virtual:bamboo.css')) {
81
- return
82
- }
83
-
84
- return { code: `${code}\nimport 'virtual:bamboo.css';\n`, map: null }
85
- },
86
- })
87
-
88
- plugins.push({
89
- name: 'xplat-bamboo:nativescript-output',
90
- enforce: 'post',
91
- options: {
92
- order: 'post',
93
- handler(inputOptions) {
94
- const options = inputOptions as typeof inputOptions & {
95
- output?: { plugins?: Plugin[] } | Array<{ plugins?: Plugin[] }>
96
- }
97
-
98
- const outputs = Array.isArray(options.output)
99
- ? options.output
100
- : options.output
101
- ? [options.output]
102
- : []
103
-
104
- // Upstream installs one finalizer per configured output. With no
105
- // output configured its options hook deliberately installs none.
106
- for (const output of outputs) {
107
- const finalizers = (output.plugins ?? [])
108
- .flat(Infinity)
109
- .filter((plugin): plugin is Plugin =>
110
- Boolean(plugin && plugin.name?.startsWith('bamboocss:output-finalizer:')),
111
- )
112
-
113
- if (!finalizers.length) {
114
- throw new Error(
115
- '@octane-xplat/bamboo: native CSS adaptation requires a bamboocss:output-finalizer:* plugin for each configured output',
116
- )
117
- }
118
-
119
- for (const finalizer of finalizers) {
120
- runBeforeNativeCss(finalizer, finalizer.name)
121
- }
122
- }
123
- },
124
- },
125
- })
126
- }
127
-
128
- plugins.push(platformOutput())
129
- return plugins
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.