@jk2908/cxx 0.1.0 → 0.1.1
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 +9 -33
- package/dist/index.cjs +0 -66
- package/dist/next/cxx-loader.cjs +0 -9
- package/dist/next/index.cjs +0 -29
- package/dist/vite-plugin-cxx/index.cjs +0 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jk2908/cxx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Jerome Kenway",
|
|
6
6
|
"repository": {
|
|
@@ -35,44 +35,20 @@
|
|
|
35
35
|
},
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
"default": "./dist/index.js"
|
|
41
|
-
},
|
|
42
|
-
"require": {
|
|
43
|
-
"types": "./dist/index.d.ts",
|
|
44
|
-
"default": "./dist/index.cjs"
|
|
45
|
-
}
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"default": "./dist/index.js"
|
|
46
40
|
},
|
|
47
41
|
"./next": {
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
"default": "./dist/next/index.js"
|
|
51
|
-
},
|
|
52
|
-
"require": {
|
|
53
|
-
"types": "./dist/next/index.d.ts",
|
|
54
|
-
"default": "./dist/next/index.cjs"
|
|
55
|
-
}
|
|
42
|
+
"types": "./dist/next/index.d.ts",
|
|
43
|
+
"default": "./dist/next/index.js"
|
|
56
44
|
},
|
|
57
45
|
"./next/cxx-loader": {
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
"default": "./dist/next/cxx-loader.js"
|
|
61
|
-
},
|
|
62
|
-
"require": {
|
|
63
|
-
"types": "./dist/next/cxx-loader.d.ts",
|
|
64
|
-
"default": "./dist/next/cxx-loader.cjs"
|
|
65
|
-
}
|
|
46
|
+
"types": "./dist/next/cxx-loader.d.ts",
|
|
47
|
+
"default": "./dist/next/cxx-loader.js"
|
|
66
48
|
},
|
|
67
49
|
"./vite-plugin-cxx": {
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
"default": "./dist/vite-plugin-cxx/index.js"
|
|
71
|
-
},
|
|
72
|
-
"require": {
|
|
73
|
-
"types": "./dist/vite-plugin-cxx/index.d.ts",
|
|
74
|
-
"default": "./dist/vite-plugin-cxx/index.cjs"
|
|
75
|
-
}
|
|
50
|
+
"types": "./dist/vite-plugin-cxx/index.d.ts",
|
|
51
|
+
"default": "./dist/vite-plugin-cxx/index.js"
|
|
76
52
|
}
|
|
77
53
|
},
|
|
78
54
|
"bugs": {
|
package/dist/index.cjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
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 cxx = (_)=>[
|
|
23
|
-
'',
|
|
24
|
-
{},
|
|
25
|
-
''
|
|
26
|
-
];
|
|
27
|
-
const varMatch = /(?:const|var|let)\s*\[(\w+|)\s*,?\s*(\w+|)\s*,?\s*(\w+|)\s*\]\s*=\s*cxx\s*`([\s\S]*?)`/gm;
|
|
28
|
-
const DEFAULT_CONFIG = {
|
|
29
|
-
lightningcss: {
|
|
30
|
-
minify: true,
|
|
31
|
-
cssModules: true
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
function inject(source, id, config = {}) {
|
|
35
|
-
try {
|
|
36
|
-
const tmpl = source.replace(varMatch, (_, ...args)=>{
|
|
37
|
-
const [varOne, varTwo, varThree, css] = args;
|
|
38
|
-
const { code, exports } = lightningcss.transform({
|
|
39
|
-
...DEFAULT_CONFIG.lightningcss,
|
|
40
|
-
...config.lightningcss,
|
|
41
|
-
filename: id,
|
|
42
|
-
code: Buffer.from(css)
|
|
43
|
-
});
|
|
44
|
-
const href = cyrb53([
|
|
45
|
-
...Object.keys(exports ?? {}),
|
|
46
|
-
id
|
|
47
|
-
].join(''));
|
|
48
|
-
const classes = exports ? Object.fromEntries(Object.entries(exports).map(([key, value])=>[
|
|
49
|
-
key,
|
|
50
|
-
value.name
|
|
51
|
-
])) : {};
|
|
52
|
-
return [
|
|
53
|
-
varOne && `const ${varOne} = \`${code}\``,
|
|
54
|
-
varTwo && `const ${varTwo} = ${JSON.stringify(classes)}`,
|
|
55
|
-
varThree && `const ${varThree} = \`${href}\``
|
|
56
|
-
].filter(Boolean).join('\n');
|
|
57
|
-
});
|
|
58
|
-
return tmpl;
|
|
59
|
-
} catch (err) {
|
|
60
|
-
console.error('cxx error :(', err);
|
|
61
|
-
return source;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
exports.cxx = cxx;
|
|
66
|
-
exports.inject = inject;
|
package/dist/next/cxx-loader.cjs
DELETED
package/dist/next/index.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
|
|
3
|
-
var path = require('node:path');
|
|
4
|
-
|
|
5
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
-
|
|
7
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
8
|
-
|
|
9
|
-
function withCxx(nextConfig = {}, config) {
|
|
10
|
-
return {
|
|
11
|
-
...nextConfig,
|
|
12
|
-
webpack (conf, options) {
|
|
13
|
-
const resolvedNextConfig = typeof nextConfig?.webpack === 'function' ? nextConfig?.webpack(conf, options) : conf;
|
|
14
|
-
resolvedNextConfig?.module?.rules?.push({
|
|
15
|
-
test: /\.(js|jsx|ts|tsx)$/,
|
|
16
|
-
exclude: /node_modules/,
|
|
17
|
-
use: {
|
|
18
|
-
loader: path__default.default.resolve(__dirname, 'cxx-loader.js'),
|
|
19
|
-
options: {
|
|
20
|
-
...config
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return resolvedNextConfig;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
exports.withCxx = withCxx;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
|
|
3
|
-
var index_cjs = require('../index.cjs');
|
|
4
|
-
|
|
5
|
-
function vitePluginCxx(config) {
|
|
6
|
-
return {
|
|
7
|
-
name: 'cxx',
|
|
8
|
-
enforce: 'pre',
|
|
9
|
-
transform (code, id) {
|
|
10
|
-
return {
|
|
11
|
-
code: index_cjs.inject(code, id, config),
|
|
12
|
-
map: null
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
exports.default = vitePluginCxx;
|