@octane-xplat/bamboo 0.14.0 → 0.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octane-xplat/bamboo",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Bamboo CSS integration defaults for Octane xplat apps",
5
5
  "keywords": [
6
6
  "bamboo",
@@ -17,13 +17,25 @@
17
17
  "directory": "packages/bamboo"
18
18
  },
19
19
  "files": [
20
- "src"
20
+ "src",
21
+ "types",
22
+ "!src/**/*.test.*",
23
+ "!src/**/*.spec.*"
21
24
  ],
22
25
  "type": "module",
23
26
  "exports": {
24
- ".": "./src/config.ts",
25
- "./config": "./src/config.ts",
26
- "./vite": "./src/vite.ts"
27
+ ".": {
28
+ "types": "./types/generated/config.d.ts",
29
+ "default": "./src/config.ts"
30
+ },
31
+ "./config": {
32
+ "types": "./types/generated/config.d.ts",
33
+ "default": "./src/config.ts"
34
+ },
35
+ "./vite": {
36
+ "types": "./types/generated/vite.d.ts",
37
+ "default": "./src/vite.ts"
38
+ }
27
39
  },
28
40
  "publishConfig": {
29
41
  "access": "public"
@@ -33,7 +45,14 @@
33
45
  "@bamboocss/types": "1.56.2",
34
46
  "@bamboocss/vite": "1.56.2"
35
47
  },
48
+ "devDependencies": {
49
+ "typescript": "5.9.3"
50
+ },
36
51
  "peerDependencies": {
37
52
  "vite": ">=5"
53
+ },
54
+ "scripts": {
55
+ "test:packed": "node tests/packed-consumer.mjs",
56
+ "typegen": "tsc -p tsconfig.types.json"
38
57
  }
39
58
  }
package/src/config.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { preset as presetBase } from '@bamboocss/preset-base'
2
2
  import type { Preset, Theme, UserConfig, UtilityConfig } from '@bamboocss/types'
3
3
 
4
+ // Bamboo 1.56.2 has no flexWrap utility. Keep it outside this selected subset
5
+ // rather than promising a utility that cannot be generated.
4
6
  const portableProperties = [
5
7
  'alignItems',
6
8
  'alignSelf',
@@ -13,7 +15,6 @@ const portableProperties = [
13
15
  'flexDirection',
14
16
  'flexGrow',
15
17
  'flexShrink',
16
- 'flexWrap',
17
18
  'fontFamily',
18
19
  'fontSize',
19
20
  'fontWeight',
@@ -52,15 +53,17 @@ const radii = Object.fromEntries(
52
53
  )
53
54
 
54
55
  const portableUtilities = Object.fromEntries(
55
- portableProperties.flatMap((property) => {
56
+ portableProperties.map((property) => {
56
57
  const config = presetBase.utilities[property]
57
58
  if (!config) {
58
- return []
59
+ throw new Error(
60
+ `@octane-xplat/bamboo: missing portable utility "${property}" in @bamboocss/preset-base`,
61
+ )
59
62
  }
60
63
 
61
64
  // Bamboo's default margin scale includes `auto`, which NativeScript
62
65
  // ignores; expose token spacing only in the shared preset.
63
- return [[property, property.startsWith('margin') ? { ...config, values: 'spacing' } : config]]
66
+ return [property, property.startsWith('margin') ? { ...config, values: 'spacing' } : config]
64
67
  }),
65
68
  ) as UtilityConfig
66
69
 
package/src/vite.ts CHANGED
@@ -1,4 +1,18 @@
1
1
  import { bamboocss, type BambooVitePluginOptions } from '@bamboocss/vite'
2
+ import type { Plugin } from 'vite'
3
+
4
+ function runBeforeNativeCss(plugin: Plugin | undefined, anchor: string) {
5
+ const hook = plugin?.generateBundle
6
+ if (plugin && typeof hook === 'function') {
7
+ plugin.generateBundle = { order: 'pre', handler: hook }
8
+ } else if (hook && typeof hook === 'object' && typeof hook.handler === 'function') {
9
+ hook.order = 'pre'
10
+ } else {
11
+ throw new Error(
12
+ `@octane-xplat/bamboo: native CSS adaptation requires ${anchor} with a generateBundle handler`,
13
+ )
14
+ }
15
+ }
2
16
 
3
17
  export interface XplatBambooOptions extends BambooVitePluginOptions {
4
18
  /** NativeScript consumes CSS assets in its own generateBundle hook. */
@@ -18,13 +32,28 @@ export function xplatBamboo({ native = false, ...options }: XplatBambooOptions =
18
32
  // Let Bamboo prune and validate the emitted asset before NativeScript's
19
33
  // main-entry hook serializes it into the native bootstrap and removes it.
20
34
  const cssPlugin = plugins.find((plugin) => plugin.name === 'bamboocss:css')
21
- if (cssPlugin && typeof cssPlugin.generateBundle === 'object') {
22
- cssPlugin.generateBundle.order = 'pre'
23
- }
35
+ runBeforeNativeCss(cssPlugin, 'bamboocss:css')
24
36
 
37
+ let isBuild = false
25
38
  plugins.push({
26
39
  name: 'xplat-bamboo:nativescript-entry-graph',
27
40
  enforce: 'post',
41
+ configResolved(config) {
42
+ isBuild = config.command === 'build'
43
+ },
44
+ buildEnd(error) {
45
+ if (!isBuild || error) {
46
+ return
47
+ }
48
+
49
+ // Inspect the graph, including cached modules in watch builds. A
50
+ // custom entry that already imports the sheet needs no injection.
51
+ if (![...this.getModuleIds()].some((id) => id.split('?')[0] === '\0virtual:bamboo.css')) {
52
+ this.error(
53
+ '@octane-xplat/bamboo: native entry graph is missing virtual:bamboo.css; expected virtual:entry-with-polyfills or an explicit stylesheet import',
54
+ )
55
+ }
56
+ },
28
57
  transform(code, id) {
29
58
  // @nativescript/vite builds from a generated entry
30
59
  // (`virtual:entry-with-polyfills`). Under HMR that entry boots
@@ -49,13 +78,8 @@ export function xplatBamboo({ native = false, ...options }: XplatBambooOptions =
49
78
  options: {
50
79
  order: 'post',
51
80
  handler(inputOptions) {
52
- type OutputHook = {
53
- name?: string
54
- generateBundle?: { order?: string } | ((...args: never[]) => unknown)
55
- }
56
-
57
- const options = inputOptions as unknown as {
58
- output?: { plugins?: OutputHook[] } | Array<{ plugins?: OutputHook[] }>
81
+ const options = inputOptions as typeof inputOptions & {
82
+ output?: { plugins?: Plugin[] } | Array<{ plugins?: Plugin[] }>
59
83
  }
60
84
 
61
85
  const outputs = Array.isArray(options.output)
@@ -64,14 +88,23 @@ export function xplatBamboo({ native = false, ...options }: XplatBambooOptions =
64
88
  ? [options.output]
65
89
  : []
66
90
 
91
+ // Upstream installs one finalizer per configured output. With no
92
+ // output configured its options hook deliberately installs none.
67
93
  for (const output of outputs) {
68
- for (const plugin of output.plugins ?? []) {
69
- if (
70
- plugin.name?.startsWith('bamboocss:output-finalizer:') &&
71
- typeof plugin.generateBundle === 'object'
72
- ) {
73
- plugin.generateBundle.order = 'pre'
74
- }
94
+ const finalizers = (output.plugins ?? [])
95
+ .flat(Infinity)
96
+ .filter((plugin): plugin is Plugin =>
97
+ Boolean(plugin && plugin.name?.startsWith('bamboocss:output-finalizer:')),
98
+ )
99
+
100
+ if (!finalizers.length) {
101
+ throw new Error(
102
+ '@octane-xplat/bamboo: native CSS adaptation requires a bamboocss:output-finalizer:* plugin for each configured output',
103
+ )
104
+ }
105
+
106
+ for (const finalizer of finalizers) {
107
+ runBeforeNativeCss(finalizer, finalizer.name)
75
108
  }
76
109
  }
77
110
  },
@@ -0,0 +1,46 @@
1
+ import type { Preset, UtilityConfig } from '@bamboocss/types';
2
+ /**
3
+ * Utilities and tokens selected for the CSS subset shared by NativeScript and
4
+ * browsers. This intentionally omits Bamboo's full browser-oriented preset;
5
+ * apps can extend it when they have checked a property on their targets.
6
+ */
7
+ export declare const xplatPortablePreset: Preset;
8
+ /**
9
+ * Bamboo defaults for apps using the shared Octane xplat stylesheet.
10
+ *
11
+ * Pass this object to `defineConfig` from `@bamboocss/dev`, then add the app's
12
+ * `include` and `outdir`. The shared UI stylesheet declares the matching layer
13
+ * order before `virtual:bamboo.css` is imported.
14
+ */
15
+ export declare const xplatBambooConfig: {
16
+ preflight: false;
17
+ cssVarRoot: string;
18
+ layers: {
19
+ reset: string;
20
+ base: string;
21
+ tokens: string;
22
+ recipes: string;
23
+ utilities: string;
24
+ };
25
+ presets: never[];
26
+ utilities: UtilityConfig;
27
+ theme: {
28
+ tokens: {
29
+ colors: {
30
+ [k: string]: {
31
+ value: string;
32
+ };
33
+ };
34
+ radii: {
35
+ [k: string]: {
36
+ value: string;
37
+ };
38
+ };
39
+ spacing: {
40
+ [k: string]: {
41
+ value: string;
42
+ };
43
+ };
44
+ };
45
+ };
46
+ };
@@ -0,0 +1,13 @@
1
+ import { type BambooVitePluginOptions } from '@bamboocss/vite';
2
+ import type { Plugin } from 'vite';
3
+ export interface XplatBambooOptions extends BambooVitePluginOptions {
4
+ /** NativeScript consumes CSS assets in its own generateBundle hook. */
5
+ native?: boolean;
6
+ }
7
+ /**
8
+ * Create Bamboo's Vite plugins for an Octane xplat app.
9
+ *
10
+ * Pass `cwd` and `configPath` when Bamboo's source/config root differs from
11
+ * Vite's app root, as it does in the shared harness.
12
+ */
13
+ export declare function xplatBamboo({ native, ...options }?: XplatBambooOptions): Plugin<any>[];