@symbiote-native/css-parser 0.1.0 → 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 +13 -3
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/metro-transformer.d.ts +2 -1
- package/build/metro-transformer.js +22 -9
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
# @symbiote-native/css-parser
|
|
2
2
|
|
|
3
|
-
The **build-time CSS compiler** of [
|
|
3
|
+
The **build-time CSS compiler** of [SymbioteNative](../../README.md) — turns a Vue SFC `<style>` block,
|
|
4
4
|
or a standalone `.css`/`.module.css` file, into a React Native style object at build time, resolved
|
|
5
5
|
back at render time through a class-name registry shared by every adapter (React's `className`,
|
|
6
6
|
Vue's `class`/`:class`, Angular's `addClass`/`removeClass`). It also compiles SCSS/Sass, Less, and
|
|
7
7
|
Stylus sources down to plain CSS before the same pipeline runs, so scoped styles, `:global()`, and
|
|
8
8
|
CSS Modules all work identically regardless of source language.
|
|
9
9
|
|
|
10
|
-
> New to
|
|
10
|
+
> New to SymbioteNative? The [root README](../../README.md) has the architecture. Styling with CSS
|
|
11
11
|
> classes (instead of `StyleSheet.create`) is the supported convention across every example app —
|
|
12
12
|
> this package is what makes it work at build time; [`@symbiote-native/engine`](../engine)'s
|
|
13
13
|
> `style-registry` is what resolves it at runtime.
|
|
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
|
|
@@ -107,7 +117,7 @@ import {
|
|
|
107
117
|
not yet generate a typed `.d.ts` for an **inline** Vue `<style module>` block (only standalone
|
|
108
118
|
`.module.css` files get the strict, no-index-signature type — Vue's own Volar plugin gives inline
|
|
109
119
|
blocks a looser, typo-tolerant type for free) and has no Svelte support yet (no Svelte adapter
|
|
110
|
-
exists in
|
|
120
|
+
exists in SymbioteNative today).
|
|
111
121
|
|
|
112
122
|
## Related packages
|
|
113
123
|
|
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
|
|
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
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// is a regular `dependency` of every adapter
|
|
6
|
-
// @symbiote-native/angular), so this is
|
|
7
|
-
//
|
|
8
|
-
//
|
|
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
|
-
|
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbiote-native/css-parser",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Build-time CSS/SCSS/Less/Stylus compiler for
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
7
7
|
"url": "git+https://github.com/OneEyed1366/symbiote-native.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
|
},
|