@omnia/tooling-vue 8.0.99-dev → 8.0.100-dev
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/internal-do-not-import-from-here/config/omnia.fx.core_a2892051-fd9f-4056-ae8d-30d16d48417d.manifest.json +1 -1
- package/internal-do-not-import-from-here/config/omnia.fx.ux.libs_0fe5c5f2-8d89-485b-afd4-36fe3ff5943a.manifest.json +1 -1
- package/internal-do-not-import-from-here/config/omnia.vendor.manifest.json +1 -1
- package/internal-do-not-import-from-here/shared.d.ts +1 -1
- package/internal-do-not-import-from-here/shared.js +3 -3
- package/internal-do-not-import-from-here/tasks/ComponentDocRegistrations.js +1 -1
- package/internal-do-not-import-from-here/tasks/bundle.js +2 -2
- package/internal-do-not-import-from-here/tasks/doc.js +80 -65
- package/internal-do-not-import-from-here/tasks/vendor.js +4 -4
- package/internal-do-not-import-from-here/vite/hmr/graph.js +1 -1
- package/internal-do-not-import-from-here/vite/hmr/vueJsx.js +1 -20
- package/internal-do-not-import-from-here/webpack-loaders/wc-loader.js +1 -1
- package/internal-do-not-import-from-here/webpack-plugins/stylexjs/index.d.ts +53 -0
- package/internal-do-not-import-from-here/webpack-plugins/stylexjs/index.js +194 -0
- package/internal-do-not-import-from-here/webpack-plugins/stylexjs/loader.d.ts +9 -0
- package/internal-do-not-import-from-here/webpack-plugins/stylexjs/loader.js +23 -0
- package/package.json +4 -5
|
@@ -25,20 +25,25 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
|
|
|
25
25
|
let params = "";
|
|
26
26
|
if (type.params?.length > 0) {
|
|
27
27
|
type.params.forEach(p => {
|
|
28
|
-
params += `${p.value}:${
|
|
28
|
+
params += `${p.value}:${extractTypeValue(p.typeAnnotation)}, `;
|
|
29
29
|
});
|
|
30
30
|
params = params.replace(/,\s*$/, "");
|
|
31
31
|
}
|
|
32
|
-
return `(${params}) => ${
|
|
32
|
+
return `(${params}) => ${extractTypeValue(type.typeAnnotation)}`;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function extractTypeValue(tsType, rawValue = false) {
|
|
35
35
|
let result = "";
|
|
36
36
|
if (tsType.type === "TsTypeAnnotation") {
|
|
37
|
-
return
|
|
37
|
+
return extractTypeValue(tsType.typeAnnotation);
|
|
38
38
|
}
|
|
39
39
|
switch (tsType.type) {
|
|
40
40
|
case "TsLiteralType":
|
|
41
|
-
|
|
41
|
+
if (rawValue && tsType.literal.type === "StringLiteral") {
|
|
42
|
+
result = tsType.literal.raw;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
result = tsType.literal.value;
|
|
46
|
+
}
|
|
42
47
|
break;
|
|
43
48
|
case "TsKeywordType":
|
|
44
49
|
result = tsType.kind;
|
|
@@ -46,6 +51,9 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
|
|
|
46
51
|
case "TsTypeReference":
|
|
47
52
|
result = tsType.typeName.value;
|
|
48
53
|
break;
|
|
54
|
+
case "TsTypeQuery":
|
|
55
|
+
result = tsType.exprName.value;
|
|
56
|
+
break;
|
|
49
57
|
case "TsFunctionType":
|
|
50
58
|
result = getPropertyFunctionTypeAsString(tsType);
|
|
51
59
|
break;
|
|
@@ -64,7 +72,7 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
|
|
|
64
72
|
break;
|
|
65
73
|
case "vModel":
|
|
66
74
|
result.type = DefineVueType.Model;
|
|
67
|
-
result.propertyTypeAsString =
|
|
75
|
+
result.propertyTypeAsString = extractTypeValue(ce.typeArguments.params[0]);
|
|
68
76
|
result.name = result.name ? `v-model:${result.name}` : result.name;
|
|
69
77
|
break;
|
|
70
78
|
case "slots":
|
|
@@ -72,16 +80,16 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
|
|
|
72
80
|
result.propertyTypeAsObject = {};
|
|
73
81
|
ce.typeArguments.params[0].members
|
|
74
82
|
.forEach(m => {
|
|
75
|
-
result.propertyTypeAsObject[m.key.value] =
|
|
83
|
+
result.propertyTypeAsObject[m.key.value] = extractTypeValue(m.typeAnnotation);
|
|
76
84
|
});
|
|
77
85
|
break;
|
|
78
86
|
case "prop":
|
|
79
87
|
result.type = DefineVueType.Prop;
|
|
80
|
-
result.propertyTypeAsString =
|
|
88
|
+
result.propertyTypeAsString = extractTypeValue(ce.typeArguments.params[0]);
|
|
81
89
|
break;
|
|
82
90
|
case "emit":
|
|
83
91
|
result.type = DefineVueType.Emit;
|
|
84
|
-
result.propertyTypeAsString =
|
|
92
|
+
result.propertyTypeAsString = extractTypeValue(ce.typeArguments.params[0]);
|
|
85
93
|
break;
|
|
86
94
|
default:
|
|
87
95
|
getPropertyInfo(ce.callee.object, result);
|
|
@@ -91,6 +99,7 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
|
|
|
91
99
|
async function buildDoc(wc) {
|
|
92
100
|
try {
|
|
93
101
|
const wcPath = (0, shared_1.convertManifestPathToEntryPath)(wc.manifestPath, [wc.componentOptions.entryPoint])[0];
|
|
102
|
+
const elementName = wc.componentOptions.elementName;
|
|
94
103
|
const wcParseResult = await (0, core_1.parseFile)(wcPath, {
|
|
95
104
|
syntax: 'typescript',
|
|
96
105
|
target: 'es2020',
|
|
@@ -101,6 +110,14 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
|
|
|
101
110
|
wcParseResult.body.forEach(b => {
|
|
102
111
|
if (b.type === 'ExportDefaultExpression'
|
|
103
112
|
&& b.expression.callee?.value === "defineVueComponent") {
|
|
113
|
+
if (!docResult[elementName]) {
|
|
114
|
+
docResult[elementName] = {
|
|
115
|
+
emits: {},
|
|
116
|
+
models: {},
|
|
117
|
+
props: {},
|
|
118
|
+
slots: {}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
104
121
|
if (b.expression.arguments[0].expression.type === "ArrowFunctionExpression") {
|
|
105
122
|
const params = b.expression.arguments[0].expression.params;
|
|
106
123
|
const typeParams = params[0].typeAnnotation.typeAnnotation.typeParams.params;
|
|
@@ -108,56 +125,62 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
|
|
|
108
125
|
props.types.forEach((t) => {
|
|
109
126
|
const typeName = t.typeName.value;
|
|
110
127
|
if (typeName === "DefineProp"
|
|
111
|
-
|| typeName === "DefineVModel"
|
|
112
|
-
|| typeName === "DefineSlot"
|
|
113
|
-
|| typeName === "DefineEmit") {
|
|
128
|
+
|| typeName === "DefineVModel") {
|
|
114
129
|
// const isDefineVModel = (t.typeName as Identifier).value === "DefineVModel$";
|
|
115
|
-
if (!docResult[wc.componentOptions.elementName]) {
|
|
116
|
-
docResult[wc.componentOptions.elementName] = {
|
|
117
|
-
emits: {},
|
|
118
|
-
models: {},
|
|
119
|
-
props: {},
|
|
120
|
-
slots: {}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
130
|
const params = t.typeParams.params;
|
|
124
|
-
const name =
|
|
125
|
-
const type =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
else { // props
|
|
137
|
-
docResult[wc.componentOptions.elementName].props[name] = {
|
|
138
|
-
type: type,
|
|
139
|
-
description: description,
|
|
140
|
-
required: required.toString().toLowerCase() === "true" ? true : false
|
|
141
|
-
};
|
|
142
|
-
}
|
|
131
|
+
const name = extractTypeValue(params[0]) || "modelValue";
|
|
132
|
+
const type = extractTypeValue(params[1]);
|
|
133
|
+
const required = params.length > 2 ? extractTypeValue(params[2]) : false;
|
|
134
|
+
const defaultValue = params.length > 3 ? extractTypeValue(params[3], true) : undefined;
|
|
135
|
+
const description = params.length > 4 ? extractTypeValue(params[4]) : "";
|
|
136
|
+
const info = {
|
|
137
|
+
type: type,
|
|
138
|
+
description: description,
|
|
139
|
+
required: required.toString().toLowerCase() === "true" ? true : false
|
|
140
|
+
};
|
|
141
|
+
if (defaultValue !== undefined) {
|
|
142
|
+
info.defaultValue = defaultValue;
|
|
143
143
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
description: description,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
else { // slots
|
|
153
|
-
docResult[wc.componentOptions.elementName].slots[name] = {
|
|
154
|
-
type: type,
|
|
155
|
-
description: description,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
144
|
+
if (typeName === "DefineVModel") {
|
|
145
|
+
docResult[wc.componentOptions.elementName].models[name] = info;
|
|
146
|
+
}
|
|
147
|
+
else { // props
|
|
148
|
+
docResult[wc.componentOptions.elementName].props[name] = info;
|
|
158
149
|
}
|
|
159
150
|
}
|
|
160
151
|
});
|
|
152
|
+
if (typeParams.length > 1) {
|
|
153
|
+
const emits = typeParams[1];
|
|
154
|
+
emits.types.forEach((t) => {
|
|
155
|
+
const typeName = t.typeName.value;
|
|
156
|
+
if (typeName === "DefineEmit") {
|
|
157
|
+
const params = t.typeParams.params;
|
|
158
|
+
const name = extractTypeValue(params[0]);
|
|
159
|
+
const type = extractTypeValue(params[1]);
|
|
160
|
+
const description = params.length > 2 ? extractTypeValue(params[2]) : "";
|
|
161
|
+
docResult[elementName].emits[name] = {
|
|
162
|
+
type: type,
|
|
163
|
+
description: description,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (typeParams.length > 2) {
|
|
169
|
+
const slots = typeParams[2];
|
|
170
|
+
slots.types.forEach((t) => {
|
|
171
|
+
const typeName = t.typeName.value;
|
|
172
|
+
if (typeName === "DefineSlot") {
|
|
173
|
+
const params = t.typeParams.params;
|
|
174
|
+
const name = extractTypeValue(params[0]);
|
|
175
|
+
const type = extractTypeValue(params[1]);
|
|
176
|
+
const description = params.length > 2 ? extractTypeValue(params[2]) : "";
|
|
177
|
+
docResult[elementName].slots[name] = {
|
|
178
|
+
type: type,
|
|
179
|
+
description: description,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
161
184
|
}
|
|
162
185
|
else {
|
|
163
186
|
b.expression.arguments[0].expression
|
|
@@ -175,29 +198,21 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
|
|
|
175
198
|
name: ""
|
|
176
199
|
};
|
|
177
200
|
getPropertyInfo(em, PropertyResult);
|
|
178
|
-
if (!docResult[wc.componentOptions.elementName]) {
|
|
179
|
-
docResult[wc.componentOptions.elementName] = {
|
|
180
|
-
emits: {},
|
|
181
|
-
models: {},
|
|
182
|
-
props: {},
|
|
183
|
-
slots: {}
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
201
|
switch (PropertyResult.type) {
|
|
187
202
|
case DefineVueType.Prop:
|
|
188
|
-
docResult[
|
|
203
|
+
docResult[elementName].props[PropertyResult.name] = {
|
|
189
204
|
type: PropertyResult.propertyTypeAsString,
|
|
190
205
|
description: em.arguments[0].expression.value
|
|
191
206
|
};
|
|
192
207
|
break;
|
|
193
208
|
case DefineVueType.Model:
|
|
194
|
-
docResult[
|
|
209
|
+
docResult[elementName].models[PropertyResult.name] = {
|
|
195
210
|
type: PropertyResult.propertyTypeAsString,
|
|
196
211
|
description: em.arguments[0].expression.value
|
|
197
212
|
};
|
|
198
213
|
break;
|
|
199
214
|
case DefineVueType.Emit:
|
|
200
|
-
docResult[
|
|
215
|
+
docResult[elementName].emits[PropertyResult.name] = {
|
|
201
216
|
type: PropertyResult.propertyTypeAsString,
|
|
202
217
|
description: em.arguments[0].expression.value
|
|
203
218
|
};
|
|
@@ -207,7 +222,7 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
|
|
|
207
222
|
.properties
|
|
208
223
|
.forEach(p => {
|
|
209
224
|
const slotName = p.key.value;
|
|
210
|
-
docResult[
|
|
225
|
+
docResult[elementName].slots[slotName] = {
|
|
211
226
|
type: PropertyResult.propertyTypeAsObject[slotName],
|
|
212
227
|
description: p.value.value
|
|
213
228
|
};
|
|
@@ -173,9 +173,9 @@ $.webpack({
|
|
|
173
173
|
},
|
|
174
174
|
entry: {
|
|
175
175
|
vendor: [
|
|
176
|
-
|
|
176
|
+
"@stylexjs/stylex",
|
|
177
177
|
// "tslib",
|
|
178
|
-
"./client/fx/vue/VueBundler",
|
|
178
|
+
"./client/fx/vue/VueBundler.ts",
|
|
179
179
|
"lodash.isequal",
|
|
180
180
|
"typestyle",
|
|
181
181
|
"csx",
|
|
@@ -329,9 +329,9 @@ $.webpack({
|
|
|
329
329
|
},
|
|
330
330
|
entry: {
|
|
331
331
|
vendor: [
|
|
332
|
-
|
|
332
|
+
"@stylexjs/stylex",
|
|
333
333
|
// "tslib",
|
|
334
|
-
"./client/fx/vue/VueBundler",
|
|
334
|
+
"./client/fx/vue/VueBundler.ts",
|
|
335
335
|
"lodash.isequal",
|
|
336
336
|
"typestyle",
|
|
337
337
|
"csx",
|
|
@@ -153,7 +153,7 @@ async function buildFileGraph(unknownId, code) {
|
|
|
153
153
|
return { fileGraph, code };
|
|
154
154
|
}
|
|
155
155
|
fileGraph.js.scanned = true;
|
|
156
|
-
code = (0, shared_1.
|
|
156
|
+
code = (0, shared_1.transformVueComponent)(code, fileGraph.id);
|
|
157
157
|
const esbuildTransformResult = await (0, vite_1.transformWithEsbuild)(code, id, esbuildTransformOptions);
|
|
158
158
|
code = esbuildTransformResult.code;
|
|
159
159
|
// d.ts or interface only
|
|
@@ -5,7 +5,6 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const node_crypto_1 = require("node:crypto");
|
|
6
6
|
const core_1 = require("@babel/core");
|
|
7
7
|
const $ = tslib_1.__importStar(require("../../variables"));
|
|
8
|
-
const babel_plugin_1 = tslib_1.__importDefault(require("@stylexjs/babel-plugin"));
|
|
9
8
|
function transformVueJsx(code, id) {
|
|
10
9
|
const result = (0, core_1.transformSync)(code, {
|
|
11
10
|
ast: true,
|
|
@@ -17,25 +16,7 @@ function transformVueJsx(code, id) {
|
|
|
17
16
|
: './client/tooling/vue/babel/preset-jsx.ts'
|
|
18
17
|
],
|
|
19
18
|
],
|
|
20
|
-
plugins: [
|
|
21
|
-
[
|
|
22
|
-
babel_plugin_1.default,
|
|
23
|
-
{
|
|
24
|
-
dev: true,
|
|
25
|
-
// Set this to true for snapshot testing
|
|
26
|
-
// default: false
|
|
27
|
-
test: false,
|
|
28
|
-
// Required for CSS variable support
|
|
29
|
-
unstable_moduleResolution: {
|
|
30
|
-
// type: 'commonJS' | 'haste'
|
|
31
|
-
// default: 'commonJS'
|
|
32
|
-
type: 'commonJS',
|
|
33
|
-
// The absolute path to the root directory of your project
|
|
34
|
-
rootDir: __dirname,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
]
|
|
19
|
+
plugins: []
|
|
39
20
|
});
|
|
40
21
|
// check for hmr injection
|
|
41
22
|
const declaredComponents = [];
|
|
@@ -5,7 +5,7 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
5
5
|
const shared_1 = require("../shared");
|
|
6
6
|
function default_1(content, context) {
|
|
7
7
|
const filePath = "./" + path_1.default.relative(process.cwd(), this.resourcePath).replace(/\\/g, "/");
|
|
8
|
-
content = (0, shared_1.
|
|
8
|
+
content = (0, shared_1.transformVueComponent)(content, filePath);
|
|
9
9
|
return content;
|
|
10
10
|
}
|
|
11
11
|
exports.default = default_1;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
type PluginOptions = {
|
|
10
|
+
dev?: boolean;
|
|
11
|
+
stylexImports?: string[];
|
|
12
|
+
babelConfig?: {
|
|
13
|
+
plugins?: any;
|
|
14
|
+
presets?: any;
|
|
15
|
+
babelrc?: boolean;
|
|
16
|
+
};
|
|
17
|
+
filename?: string;
|
|
18
|
+
appendTo?: string;
|
|
19
|
+
useCSSLayers?: boolean;
|
|
20
|
+
runtimeInjection?: boolean;
|
|
21
|
+
classNamePrefix?: string;
|
|
22
|
+
unstable_moduleResolution?: any;
|
|
23
|
+
};
|
|
24
|
+
export declare class StylexPlugin {
|
|
25
|
+
stylexRules: {};
|
|
26
|
+
filesInLastRun: any;
|
|
27
|
+
dev: boolean;
|
|
28
|
+
appendTo: any;
|
|
29
|
+
filename: string;
|
|
30
|
+
stylexImports: string[];
|
|
31
|
+
unstable_moduleResolution: {
|
|
32
|
+
type: string;
|
|
33
|
+
rootDir: string;
|
|
34
|
+
};
|
|
35
|
+
babelConfig: {
|
|
36
|
+
plugins: any[];
|
|
37
|
+
presets: any[];
|
|
38
|
+
babelrc: boolean;
|
|
39
|
+
};
|
|
40
|
+
useCSSLayers: boolean;
|
|
41
|
+
defaultOptions: PluginOptions;
|
|
42
|
+
babelPlugin: any;
|
|
43
|
+
constructor(options?: PluginOptions);
|
|
44
|
+
apply(compiler: any): void;
|
|
45
|
+
transformCode(inputCode: string, filename: any, logger: any): Promise<{
|
|
46
|
+
code: any;
|
|
47
|
+
map: any;
|
|
48
|
+
} | {
|
|
49
|
+
code: string;
|
|
50
|
+
map?: undefined;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.StylexPlugin = void 0;
|
|
12
|
+
const tslib_1 = require("tslib");
|
|
13
|
+
const core_1 = require("@babel/core");
|
|
14
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
15
|
+
const babel_plugin_1 = tslib_1.__importDefault(require("@stylexjs/babel-plugin"));
|
|
16
|
+
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
17
|
+
// import * as flowSyntaxPlugin from '@babel/plugin-syntax-flow';
|
|
18
|
+
// import * as jsxSyntaxPlugin from '@babel/plugin-syntax-jsx';
|
|
19
|
+
// import * as typescriptSyntaxPlugin from '@babel/plugin-syntax-typescript';
|
|
20
|
+
const promises_1 = tslib_1.__importDefault(require("fs/promises"));
|
|
21
|
+
const $ = tslib_1.__importStar(require("../../variables"));
|
|
22
|
+
const { NormalModule, Compilation } = webpack_1.default;
|
|
23
|
+
const PLUGIN_NAME = 'stylex';
|
|
24
|
+
const IS_DEV_ENV = process.env.NODE_ENV === 'development' ||
|
|
25
|
+
process.env.BABEL_ENV === 'development';
|
|
26
|
+
const { RawSource, ConcatSource } = webpack_1.default.sources;
|
|
27
|
+
class StylexPlugin {
|
|
28
|
+
constructor(options = {}) {
|
|
29
|
+
this.stylexRules = {};
|
|
30
|
+
this.filesInLastRun = null;
|
|
31
|
+
this.dev = IS_DEV_ENV;
|
|
32
|
+
this.appendTo = null;
|
|
33
|
+
this.filename = "stylex.css";
|
|
34
|
+
this.stylexImports = ['stylex', '@stylexjs/stylex'];
|
|
35
|
+
this.unstable_moduleResolution = { type: 'commonJS', rootDir: process.cwd() };
|
|
36
|
+
this.babelConfig = { plugins: [], presets: [], babelrc: false };
|
|
37
|
+
this.useCSSLayers = false;
|
|
38
|
+
this.defaultOptions = {
|
|
39
|
+
dev: IS_DEV_ENV,
|
|
40
|
+
appendTo: null,
|
|
41
|
+
filename: "stylex.css",
|
|
42
|
+
stylexImports: ['stylex', '@stylexjs/stylex'],
|
|
43
|
+
unstable_moduleResolution: { type: 'commonJS', rootDir: process.cwd() },
|
|
44
|
+
babelConfig: { plugins: [], presets: [], babelrc: false },
|
|
45
|
+
useCSSLayers: false
|
|
46
|
+
};
|
|
47
|
+
Object.assign(this, this.defaultOptions, options);
|
|
48
|
+
this.babelPlugin = [
|
|
49
|
+
babel_plugin_1.default,
|
|
50
|
+
{
|
|
51
|
+
dev: this.dev,
|
|
52
|
+
unstable_moduleResolution: this.unstable_moduleResolution,
|
|
53
|
+
importSources: this.stylexImports,
|
|
54
|
+
...options,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
apply(compiler) {
|
|
59
|
+
compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
|
|
60
|
+
// Apply loader to JS modules.
|
|
61
|
+
NormalModule.getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (loaderContext, module) => {
|
|
62
|
+
if (
|
|
63
|
+
// .js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, .cts
|
|
64
|
+
/\.ts[x]?$/.test(path_1.default.extname(module.resource))) {
|
|
65
|
+
// It might make sense to use .push() here instead of .unshift()
|
|
66
|
+
// Webpack usually runs loaders in reverse order and we want to ideally run
|
|
67
|
+
// our loader before anything else.
|
|
68
|
+
module.loaders.unshift({
|
|
69
|
+
loader: path_1.default.resolve(__dirname, $.isExtensionEnv ? 'loader.js' : 'loader.ts'),
|
|
70
|
+
options: { stylexPlugin: this },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
// Make a list of all modules that were included in the last compilation.
|
|
75
|
+
// This might need to be tweaked if not all files are included after a change
|
|
76
|
+
compilation.hooks.finishModules.tap(PLUGIN_NAME, (modules) => {
|
|
77
|
+
this.filesInLastRun = [...modules.values()].map((m) => m.resource);
|
|
78
|
+
});
|
|
79
|
+
const getStyleXRules = () => {
|
|
80
|
+
const { stylexRules } = this;
|
|
81
|
+
if (Object.keys(stylexRules).length === 0) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
// Take styles for the modules that were included in the last compilation.
|
|
85
|
+
const allRules = Object.keys(stylexRules)
|
|
86
|
+
.filter((filename) => this.filesInLastRun == null
|
|
87
|
+
? true
|
|
88
|
+
: this.filesInLastRun.includes(filename))
|
|
89
|
+
.map((filename) => stylexRules[filename])
|
|
90
|
+
.flat();
|
|
91
|
+
return babel_plugin_1.default.processStylexRules(allRules, this.useCSSLayers);
|
|
92
|
+
};
|
|
93
|
+
if (this.appendTo) {
|
|
94
|
+
compilation.hooks.processAssets.tap({
|
|
95
|
+
name: PLUGIN_NAME,
|
|
96
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS, // see below for more stages
|
|
97
|
+
}, (assets) => {
|
|
98
|
+
const cssFileName = Object.keys(assets).find(typeof this.appendTo === 'function'
|
|
99
|
+
? this.appendTo
|
|
100
|
+
: (filename) => filename.endsWith(this.appendTo));
|
|
101
|
+
if (cssFileName) {
|
|
102
|
+
const cssAsset = assets[cssFileName];
|
|
103
|
+
const stylexCSS = getStyleXRules();
|
|
104
|
+
if (stylexCSS != null) {
|
|
105
|
+
assets[cssFileName] = new ConcatSource(cssAsset, new RawSource(stylexCSS));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// We'll emit an asset ourselves. This comes with some complications in from Webpack.
|
|
112
|
+
// If the filename contains replacement tokens, like [contenthash], we need to
|
|
113
|
+
// process those tokens ourselves. Webpack does provide a way to reuse the configured
|
|
114
|
+
// hashing functions. We'll take advantage of that to process tokens.
|
|
115
|
+
const getContentHash = (source) => {
|
|
116
|
+
const { outputOptions } = compilation;
|
|
117
|
+
const { hashDigest, hashDigestLength, hashFunction, hashSalt } = outputOptions;
|
|
118
|
+
const hash = compiler.webpack.util.createHash(hashFunction);
|
|
119
|
+
if (hashSalt) {
|
|
120
|
+
hash.update(hashSalt);
|
|
121
|
+
}
|
|
122
|
+
hash.update(source);
|
|
123
|
+
const fullContentHash = hash.digest(hashDigest);
|
|
124
|
+
return fullContentHash.toString().slice(0, hashDigestLength);
|
|
125
|
+
};
|
|
126
|
+
// Consume collected rules and emit the stylex CSS asset
|
|
127
|
+
compilation.hooks.processAssets.tap({
|
|
128
|
+
name: PLUGIN_NAME,
|
|
129
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
|
|
130
|
+
}, () => {
|
|
131
|
+
try {
|
|
132
|
+
const collectedCSS = getStyleXRules();
|
|
133
|
+
if (collectedCSS) {
|
|
134
|
+
// build up a content hash for the rules using webpack's configured hashing functions
|
|
135
|
+
const contentHash = getContentHash(collectedCSS);
|
|
136
|
+
// pretend to be a chunk so we can reuse the webpack routine to process the filename and do token replacement
|
|
137
|
+
// see https://github.com/webpack/webpack/blob/main/lib/Compilation.js#L4733
|
|
138
|
+
// see https://github.com/webpack/webpack/blob/main/lib/TemplatedPathPlugin.js#L102
|
|
139
|
+
const data = {
|
|
140
|
+
filename: this.filename,
|
|
141
|
+
contentHash: contentHash,
|
|
142
|
+
chunk: {
|
|
143
|
+
id: this.filename,
|
|
144
|
+
name: path_1.default.parse(this.filename).name,
|
|
145
|
+
hash: contentHash,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
const { path: hashedPath, info: assetsInfo } = compilation.getPathWithInfo(data.filename, data);
|
|
149
|
+
compilation.emitAsset(hashedPath, new RawSource(collectedCSS), assetsInfo);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
compilation.errors.push(e);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
// This function is not called by Webpack directly.
|
|
160
|
+
// Instead, `NormalModule.getCompilationHooks` is used to inject a loader
|
|
161
|
+
// for JS modules. The loader than calls this function.
|
|
162
|
+
async transformCode(inputCode, filename, logger) {
|
|
163
|
+
if (this.stylexImports.some((importName) => inputCode.includes(importName))) {
|
|
164
|
+
const originalSource = this.babelConfig.babelrc
|
|
165
|
+
? await promises_1.default.readFile(filename, 'utf8')
|
|
166
|
+
: inputCode;
|
|
167
|
+
const { code, map, metadata } = await (0, core_1.transformAsync)(originalSource, {
|
|
168
|
+
babelrc: this.babelConfig.babelrc,
|
|
169
|
+
filename,
|
|
170
|
+
// Use TypeScript syntax plugin if the filename ends with `.ts` or `.tsx`
|
|
171
|
+
// and use the Flow syntax plugin otherwise.
|
|
172
|
+
plugins: [
|
|
173
|
+
// ...this.babelConfig.plugins,
|
|
174
|
+
// path.extname(filename) === '.ts'
|
|
175
|
+
// ? typescriptSyntaxPlugin
|
|
176
|
+
// : path.extname(filename) === '.tsx'
|
|
177
|
+
// ? [typescriptSyntaxPlugin, { isTSX: true }]
|
|
178
|
+
// : flowSyntaxPlugin,
|
|
179
|
+
// jsxSyntaxPlugin,
|
|
180
|
+
this.babelPlugin,
|
|
181
|
+
],
|
|
182
|
+
presets: this.babelConfig.presets,
|
|
183
|
+
});
|
|
184
|
+
if (metadata.stylex != null && metadata.stylex.length > 0) {
|
|
185
|
+
this.stylexRules[filename] = metadata.stylex;
|
|
186
|
+
}
|
|
187
|
+
if (!this.babelConfig.babelrc) {
|
|
188
|
+
return { code, map };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { code: inputCode };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.StylexPlugin = StylexPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export default function stylexLoader(inputCode: any): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
'use strict';
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
const PLUGIN_NAME = 'stylex';
|
|
12
|
+
function stylexLoader(inputCode) {
|
|
13
|
+
const callback = this.async();
|
|
14
|
+
const { stylexPlugin } = this.getOptions();
|
|
15
|
+
const logger = this._compiler.getInfrastructureLogger(PLUGIN_NAME);
|
|
16
|
+
stylexPlugin.transformCode(inputCode, this.resourcePath, logger).then(({ code, map }) => {
|
|
17
|
+
callback(null, code, map);
|
|
18
|
+
}, (error) => {
|
|
19
|
+
callback(error);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.default = stylexLoader;
|
|
23
|
+
;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnia/tooling-vue",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "8.0.
|
|
4
|
+
"version": "8.0.100-dev",
|
|
5
5
|
"description": "Used to bundle and serve manifests web component that build on Vue framework.",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
],
|
|
20
20
|
"author": "Precio Fishbone",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@omnia/fx-models": "8.0.
|
|
23
|
-
"@omnia/tooling-composers": "8.0.
|
|
22
|
+
"@omnia/fx-models": "8.0.100-dev",
|
|
23
|
+
"@omnia/tooling-composers": "8.0.100-dev",
|
|
24
24
|
"@types/mousetrap": "1.5.34",
|
|
25
25
|
"@types/quill": "1.3.6",
|
|
26
26
|
"@types/zepto": "1.0.29",
|
|
27
|
-
"@babel/core": "7.
|
|
27
|
+
"@babel/core": "7.23.7",
|
|
28
28
|
"babel-loader": "8.3.0",
|
|
29
29
|
"@vue/babel-plugin-jsx": "1.1.1",
|
|
30
30
|
"circular-dependency-plugin": "5.2.2",
|
|
@@ -60,7 +60,6 @@
|
|
|
60
60
|
"vite-plugin-inspect": "0.8.1",
|
|
61
61
|
"appdata-path": "1.0.0",
|
|
62
62
|
"url": "0.11.0",
|
|
63
|
-
"@stylexjs/webpack-plugin": "0.4.1",
|
|
64
63
|
"@stylexjs/babel-plugin": "0.4.1"
|
|
65
64
|
},
|
|
66
65
|
"bugs": {
|