@jk2908/cxx 0.1.5-canary.4 → 0.1.5
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/dist/inject/index.cjs +60 -0
- package/dist/next/cxx-loader.cjs +9 -0
- package/dist/next/index.js +16 -12
- package/package.json +89 -87
- package/src/next/index.ts +19 -11
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
var lightningcss = require('lightningcss');
|
|
4
|
+
|
|
5
|
+
// cyrb53 (c) 2018 bryc (github.com/bryc)
|
|
6
|
+
// https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js
|
|
7
|
+
function cyrb53(str, seed = 0) {
|
|
8
|
+
let h1 = 0xdeadbeef ^ seed;
|
|
9
|
+
let h2 = 0x41c6ce57 ^ seed;
|
|
10
|
+
for(let i = 0, ch; i < str.length; i++){
|
|
11
|
+
ch = str.charCodeAt(i);
|
|
12
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
13
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
14
|
+
}
|
|
15
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
|
|
16
|
+
h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
17
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
|
|
18
|
+
h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
19
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const varMatch = /(?:const|var|let)\s*\[(\w+|)\s*,?\s*(\w+|)\s*,?\s*(\w+|)\s*\]\s*=\s*cxx\s*`([\s\S]*?)`/gm;
|
|
23
|
+
const DEFAULT_CONFIG = {
|
|
24
|
+
lightningcss: {
|
|
25
|
+
minify: true,
|
|
26
|
+
cssModules: true
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function inject(source, id, config = {}) {
|
|
30
|
+
try {
|
|
31
|
+
const tmpl = source.replace(varMatch, (_, ...args)=>{
|
|
32
|
+
const [varOne, varTwo, varThree, css] = args;
|
|
33
|
+
const { code, exports } = lightningcss.transform({
|
|
34
|
+
...DEFAULT_CONFIG.lightningcss,
|
|
35
|
+
...config.lightningcss,
|
|
36
|
+
filename: id,
|
|
37
|
+
code: Buffer.from(css)
|
|
38
|
+
});
|
|
39
|
+
const href = cyrb53([
|
|
40
|
+
...Object.keys(exports ?? {}),
|
|
41
|
+
id
|
|
42
|
+
].join(''));
|
|
43
|
+
const classes = exports ? Object.fromEntries(Object.entries(exports).map(([key, value])=>[
|
|
44
|
+
key,
|
|
45
|
+
value.name
|
|
46
|
+
])) : {};
|
|
47
|
+
return [
|
|
48
|
+
varOne && `const ${varOne} = \`${code}\``,
|
|
49
|
+
varTwo && `const ${varTwo} = ${JSON.stringify(classes)}`,
|
|
50
|
+
varThree && `const ${varThree} = \`${href}\``
|
|
51
|
+
].filter(Boolean).join('\n');
|
|
52
|
+
});
|
|
53
|
+
return tmpl;
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error('cxx error :(', err);
|
|
56
|
+
return source;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.inject = inject;
|
package/dist/next/index.js
CHANGED
|
@@ -6,18 +6,24 @@ const __filename = __node_cjsUrl.fileURLToPath(import.meta.url);
|
|
|
6
6
|
const __dirname = __node_cjsPath.dirname(__filename);
|
|
7
7
|
const require = __node_cjsModule.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
|
-
function withCxx(nextConfig = {}, config) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
function withCxx(nextConfig = {}, config = {}) {
|
|
10
|
+
const pkg = require('next/package.json');
|
|
11
|
+
const IS_CANARY = pkg.version?.includes('canary') ?? false;
|
|
12
|
+
const IS_TURBO = process.env.TURBOPACK === '1';
|
|
13
|
+
const TURBO_GLOB = '*.{tsx,jsx,ts,js}';
|
|
14
|
+
const loader = __node_cjsPath.resolve(__dirname, `cxx-loader.${IS_TURBO ? 'cjs' : 'js'}`);
|
|
12
15
|
const turboConfig = {
|
|
13
16
|
...nextConfig.turbo,
|
|
14
17
|
rules: {
|
|
15
18
|
...nextConfig.turbo?.rules ?? {},
|
|
16
|
-
|
|
19
|
+
[TURBO_GLOB]: {
|
|
17
20
|
loaders: [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
...nextConfig.turbo?.rules?.[TURBO_GLOB]?.loaders ?? [],
|
|
22
|
+
{
|
|
23
|
+
loader,
|
|
24
|
+
options: config
|
|
25
|
+
}
|
|
26
|
+
]
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
};
|
|
@@ -26,13 +32,11 @@ function withCxx(nextConfig = {}, config) {
|
|
|
26
32
|
webpack (conf, options) {
|
|
27
33
|
const resolvedWebpackConfig = typeof nextConfig?.webpack === 'function' ? nextConfig?.webpack(conf, options) : conf;
|
|
28
34
|
resolvedWebpackConfig?.module?.rules?.push({
|
|
29
|
-
test:
|
|
35
|
+
test: /\.(js|jsx|ts|tsx)$/,
|
|
30
36
|
exclude: /node_modules/,
|
|
31
37
|
use: {
|
|
32
|
-
loader
|
|
33
|
-
options:
|
|
34
|
-
...config
|
|
35
|
-
}
|
|
38
|
+
loader,
|
|
39
|
+
options: config
|
|
36
40
|
}
|
|
37
41
|
});
|
|
38
42
|
return resolvedWebpackConfig;
|
package/package.json
CHANGED
|
@@ -1,87 +1,89 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@jk2908/cxx",
|
|
3
|
-
"version": "0.1.5
|
|
4
|
-
"type": "module",
|
|
5
|
-
"author": "Jerome Kenway",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/jk2908/cxx.git"
|
|
9
|
-
},
|
|
10
|
-
"main": "./dist/index.js",
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "bunchee"
|
|
14
|
-
},
|
|
15
|
-
"devDependencies": {
|
|
16
|
-
"@biomejs/biome": "^1.8.3",
|
|
17
|
-
"@types/react": "latest",
|
|
18
|
-
"@types/react-dom": "latest",
|
|
19
|
-
"@types/webpack": "^5.28.5",
|
|
20
|
-
"bunchee": "^5.3.2",
|
|
21
|
-
"cross-env": "^7.0.3",
|
|
22
|
-
"lightningcss": "^1.27.0",
|
|
23
|
-
"next": "^15.0.0-canary.128",
|
|
24
|
-
"react": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0",
|
|
25
|
-
"react-dom": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0",
|
|
26
|
-
"typescript": "^5.5.4",
|
|
27
|
-
"vite": "^5.4.2"
|
|
28
|
-
},
|
|
29
|
-
"peerDependencies": {
|
|
30
|
-
"lightningcss": "^1.27.0",
|
|
31
|
-
"next": "^15.0.0-canary || ^15.0.0",
|
|
32
|
-
"react": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0",
|
|
33
|
-
"react-dom": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0",
|
|
34
|
-
"vite": "^4.0.0"
|
|
35
|
-
},
|
|
36
|
-
"exports": {
|
|
37
|
-
".": {
|
|
38
|
-
"types": "./dist/index.d.ts",
|
|
39
|
-
"default": "./dist/index.js"
|
|
40
|
-
},
|
|
41
|
-
"./inject": {
|
|
42
|
-
"types": "./dist/inject/index.d.ts",
|
|
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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@jk2908/cxx",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": "Jerome Kenway",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/jk2908/cxx.git"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "bunchee"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@biomejs/biome": "^1.8.3",
|
|
17
|
+
"@types/react": "latest",
|
|
18
|
+
"@types/react-dom": "latest",
|
|
19
|
+
"@types/webpack": "^5.28.5",
|
|
20
|
+
"bunchee": "^5.3.2",
|
|
21
|
+
"cross-env": "^7.0.3",
|
|
22
|
+
"lightningcss": "^1.27.0",
|
|
23
|
+
"next": "^15.0.0-canary.128",
|
|
24
|
+
"react": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0",
|
|
25
|
+
"react-dom": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0",
|
|
26
|
+
"typescript": "^5.5.4",
|
|
27
|
+
"vite": "^5.4.2"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"lightningcss": "^1.27.0",
|
|
31
|
+
"next": "^15.0.0-canary || ^15.0.0",
|
|
32
|
+
"react": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0",
|
|
33
|
+
"react-dom": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0",
|
|
34
|
+
"vite": "^4.0.0"
|
|
35
|
+
},
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./inject": {
|
|
42
|
+
"types": "./dist/inject/index.d.ts",
|
|
43
|
+
"require": "./dist/inject/index.cjs",
|
|
44
|
+
"default": "./dist/inject/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./next": {
|
|
47
|
+
"types": "./dist/next/index.d.ts",
|
|
48
|
+
"default": "./dist/next/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./next/cxx-loader": {
|
|
51
|
+
"types": "./dist/next/cxx-loader.d.ts",
|
|
52
|
+
"require": "./dist/next/cxx-loader.cjs",
|
|
53
|
+
"default": "./dist/next/cxx-loader.js"
|
|
54
|
+
},
|
|
55
|
+
"./vite-plugin-cxx": {
|
|
56
|
+
"types": "./dist/vite-plugin-cxx/index.d.ts",
|
|
57
|
+
"default": "./dist/vite-plugin-cxx/index.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"bugs": {
|
|
61
|
+
"url": "https://github.com/jk2908/cxx/issues"
|
|
62
|
+
},
|
|
63
|
+
"description": "Utilities for generating styles in React 19",
|
|
64
|
+
"files": [
|
|
65
|
+
"dist",
|
|
66
|
+
"src"
|
|
67
|
+
],
|
|
68
|
+
"homepage": "https://github.com/jk2908/cxx#readme",
|
|
69
|
+
"keywords": [
|
|
70
|
+
"react",
|
|
71
|
+
"react19",
|
|
72
|
+
"css",
|
|
73
|
+
"css-in-js",
|
|
74
|
+
"vite-plugin",
|
|
75
|
+
"webpack-loader",
|
|
76
|
+
"lightningcss",
|
|
77
|
+
"next",
|
|
78
|
+
"vite"
|
|
79
|
+
],
|
|
80
|
+
"license": "MIT",
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"next": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"vite": {
|
|
86
|
+
"optional": true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/next/index.ts
CHANGED
|
@@ -6,17 +6,27 @@ import type { WebpackConfigContext } from 'next/dist/server/config-shared'
|
|
|
6
6
|
|
|
7
7
|
import type { Config } from '../inject'
|
|
8
8
|
|
|
9
|
-
export function withCxx(nextConfig: NextConfig = {}, config
|
|
10
|
-
const
|
|
11
|
-
|
|
9
|
+
export function withCxx(nextConfig: NextConfig = {}, config: Config = {}) {
|
|
10
|
+
const pkg = require('next/package.json')
|
|
11
|
+
|
|
12
|
+
const IS_CANARY = pkg.version?.includes('canary') ?? false
|
|
13
|
+
const IS_TURBO = process.env.TURBOPACK === '1'
|
|
14
|
+
const TURBO_GLOB = '*.{tsx,jsx,ts,js}'
|
|
15
|
+
|
|
16
|
+
const loader = path.resolve(__dirname, `cxx-loader.${IS_TURBO ? 'cjs' : 'js'}`)
|
|
12
17
|
|
|
13
18
|
const turboConfig = {
|
|
14
19
|
...nextConfig.turbo,
|
|
15
20
|
rules: {
|
|
16
21
|
...(nextConfig.turbo?.rules ?? {}),
|
|
17
|
-
|
|
18
|
-
loaders: [
|
|
19
|
-
|
|
22
|
+
[TURBO_GLOB]: {
|
|
23
|
+
loaders: [
|
|
24
|
+
...(nextConfig.turbo?.rules?.[TURBO_GLOB]?.loaders ?? []),
|
|
25
|
+
{
|
|
26
|
+
loader,
|
|
27
|
+
options: config,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
20
30
|
},
|
|
21
31
|
},
|
|
22
32
|
}
|
|
@@ -29,13 +39,11 @@ export function withCxx(nextConfig: NextConfig = {}, config?: Config) {
|
|
|
29
39
|
) satisfies Configuration
|
|
30
40
|
|
|
31
41
|
resolvedWebpackConfig?.module?.rules?.push({
|
|
32
|
-
test:
|
|
42
|
+
test: /\.(js|jsx|ts|tsx)$/,
|
|
33
43
|
exclude: /node_modules/,
|
|
34
44
|
use: {
|
|
35
|
-
loader
|
|
36
|
-
options:
|
|
37
|
-
...config,
|
|
38
|
-
},
|
|
45
|
+
loader,
|
|
46
|
+
options: config,
|
|
39
47
|
},
|
|
40
48
|
})
|
|
41
49
|
|