@symbiote-native/css-parser 0.1.1 → 0.2.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 CHANGED
@@ -14,6 +14,16 @@ CSS Modules all work identically regardless of source language.
14
14
 
15
15
  ---
16
16
 
17
+ ## Install
18
+
19
+ Not installed directly by an app — each adapter package (`@symbiote-native/react`,
20
+ `@symbiote-native/vue`, `@symbiote-native/angular`) already depends on it and re-exports it via its
21
+ own `./metro-css-parser` subpath. Writing a Metro transformer for a new adapter yourself:
22
+
23
+ ```bash
24
+ npm install @symbiote-native/css-parser
25
+ ```
26
+
17
27
  ## Who calls this, and how
18
28
 
19
29
  **An app never imports this package directly.** It runs only inside a Metro transformer, on the
package/build/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { hashFilePath } from './file-scope-id.ts';
5
5
  export { compileCssFile, isCssModuleFile } from './metro-css-module.ts';
6
6
  export type { ICompiledCssFile } from './metro-css-module.ts';
7
7
  export { classNamesToDtsSource, generateModuleDts } from './generate-dts.ts';
8
- export { createCssMetroTransformer } from './metro-transformer.ts';
8
+ export { createCssMetroTransformer, resolveUpstreamTransformer } from './metro-transformer.ts';
9
9
  export type { IMetroTransformer, IMetroTransformParams } from './metro-transformer.ts';
10
10
  export { compileScss, compileSass, compileLess, compileStylus, compile, detectLanguage, isStyleFile, } from './preprocessors.ts';
11
11
  export type { IPreprocessorLanguage } from './preprocessors.ts';
package/build/index.js CHANGED
@@ -3,5 +3,5 @@ export { globalClassNamesIn } from "./global-selectors.js";
3
3
  export { hashFilePath } from "./file-scope-id.js";
4
4
  export { compileCssFile, isCssModuleFile } from "./metro-css-module.js";
5
5
  export { classNamesToDtsSource, generateModuleDts } from "./generate-dts.js";
6
- export { createCssMetroTransformer } from "./metro-transformer.js";
6
+ export { createCssMetroTransformer, resolveUpstreamTransformer } from "./metro-transformer.js";
7
7
  export { compileScss, compileSass, compileLess, compileStylus, compile, detectLanguage, isStyleFile, } from "./preprocessors.js";
@@ -7,4 +7,5 @@ export interface IMetroTransformer {
7
7
  transform: (params: IMetroTransformParams) => unknown;
8
8
  getCacheKey?: (...args: unknown[]) => string;
9
9
  }
10
- export declare function createCssMetroTransformer(upstreamTransformer: IMetroTransformer): IMetroTransformer;
10
+ export declare function resolveUpstreamTransformer(): IMetroTransformer;
11
+ export declare function createCssMetroTransformer(upstreamTransformer?: IMetroTransformer): IMetroTransformer;
@@ -1,12 +1,12 @@
1
1
  // A ready-made Metro babel transformer wrapper for .css/.scss/.sass/.less/.styl (+ their
2
- // .module.* twins) support, so a consuming app's own metro.config.js needs only a 3-line wiring
3
- // file instead of hand-rolling the "compile a style file, delegate everything else to upstream"
4
- // boilerplate three times (once per adapter's example, before this existed). @symbiote-native/css-parser
5
- // is a regular `dependency` of every adapter package (@symbiote-native/react, @symbiote-native/vue,
6
- // @symbiote-native/angular), so this is transitively resolvable from any app that already depends on one
7
- // of them — this repo's shamefully-hoist pnpm config (.npmrc) makes that resolvable without the
8
- // app adding @symbiote-native/css-parser to its own package.json. See the symbiote-sfc-style-compiler
9
- // skill.
2
+ // .module.* twins) support, so a consuming app's own metro.config.js needs only
3
+ // `babelTransformerPath: require.resolve('@symbiote-native/<adapter>/metro-css-parser')` instead of
4
+ // hand-rolling the "compile a style file, delegate everything else to upstream" boilerplate once
5
+ // per adapter's example. @symbiote-native/css-parser is a regular `dependency` of every adapter
6
+ // package (@symbiote-native/react, @symbiote-native/vue, @symbiote-native/angular), so this is
7
+ // transitively resolvable from any app that already depends on one of them — this repo's
8
+ // shamefully-hoist pnpm config (.npmrc) makes that resolvable without the app adding
9
+ // @symbiote-native/css-parser to its own package.json. See the symbiote-sfc-style-compiler skill.
10
10
  //
11
11
  // Sync vs async: `transform()` is async uniformly, for every recognized style extension
12
12
  // including plain `.css`. Metro's own `metro-transform-worker` already does
@@ -22,9 +22,22 @@
22
22
  // duplication. `return upstreamTransformer.transform(...)` as the last line of an async function
23
23
  // forwards whatever it returns (Promise or not) as this function's own resolved value with no
24
24
  // extra `await` needed; Metro awaits the whole chain regardless.
25
+ import { createRequire } from 'node:module';
25
26
  import { compileCssFile } from "./metro-css-module.js";
26
27
  import { isStyleFile } from "./preprocessors.js";
27
- export function createCssMetroTransformer(upstreamTransformer) {
28
+ // @react-native/metro-babel-transformer is a real `dependency` of this package (not merely a
29
+ // peer/dev dep), so it lands in css-parser's OWN resolvable node_modules under pnpm — no
30
+ // hoisting or `paths`-anchored require.resolve trick needed, unlike the app-local workaround
31
+ // this replaces (formerly duplicated in every adapter's example metro-css-transformer.js).
32
+ // Exported (not just used internally) so a per-framework Metro transformer that ALSO needs to
33
+ // delegate to the upstream RN transformer (the Vue SFC transformer, for its non-.vue passthrough
34
+ // branch) can reuse this instead of its own fragile direct `require('@react-native/metro-babel-
35
+ // transformer')`, which would only resolve for an external install by accident of hoisting.
36
+ export function resolveUpstreamTransformer() {
37
+ const require = createRequire(import.meta.url);
38
+ return require('@react-native/metro-babel-transformer');
39
+ }
40
+ export function createCssMetroTransformer(upstreamTransformer = resolveUpstreamTransformer()) {
28
41
  return {
29
42
  async transform(params) {
30
43
  if (!isStyleFile(params.filename))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbiote-native/css-parser",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Build-time CSS/SCSS/Less/Stylus compiler for SymbioteNative — compiles stylesheets to React Native style objects, resolved at runtime via a cross-adapter class-name registry.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,6 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
+ "@react-native/metro-babel-transformer": "0.86.0",
42
43
  "postcss": "^8.4.49",
43
44
  "postcss-value-parser": "^4.2.0"
44
45
  },