@wordpress/build 0.5.1-next.ba3aee3a2.0 → 0.5.1-next.v.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/lib/build.mjs +79 -68
- package/package.json +4 -3
package/lib/build.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import rtlcss from 'rtlcss';
|
|
|
17
17
|
import cssnano from 'cssnano';
|
|
18
18
|
import babel from 'esbuild-plugin-babel';
|
|
19
19
|
import { camelCase } from 'change-case';
|
|
20
|
+
import { NodePackageImporter } from 'sass-embedded';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Internal dependencies
|
|
@@ -107,26 +108,59 @@ const wordpressExternalsPlugin = createWordpressExternalsPlugin(
|
|
|
107
108
|
HANDLE_PREFIX
|
|
108
109
|
);
|
|
109
110
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Get SASS options for the given working directory.
|
|
113
|
+
*
|
|
114
|
+
* Uses NodePackageImporter from sass-embedded for resolving package imports
|
|
115
|
+
* (like @wordpress/base-styles) which works with any package manager (npm, pnpm, yarn).
|
|
116
|
+
*
|
|
117
|
+
* @param {string} workingDir - The directory where we're working (for NodePackageImporter).
|
|
118
|
+
* @return {Object} SASS options object with importers and loadPaths.
|
|
119
|
+
*/
|
|
120
|
+
function getSassOptions( workingDir ) {
|
|
121
|
+
return {
|
|
122
|
+
importers: [ new NodePackageImporter( workingDir ) ],
|
|
123
|
+
// loadPaths for resolving @wordpress/base-styles imports and local base-styles imports
|
|
124
|
+
loadPaths: [
|
|
125
|
+
// Package's own node_modules (for pnpm isolated deps)
|
|
126
|
+
path.join( workingDir, 'node_modules' ),
|
|
127
|
+
// Root node_modules (for npm hoisted deps)
|
|
128
|
+
path.join( ROOT_DIR, 'node_modules' ),
|
|
129
|
+
// For local imports like @use "mixins"
|
|
130
|
+
path.join( PACKAGES_DIR, 'base-styles' ),
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Create style bundling plugins with the given working directory.
|
|
137
|
+
*
|
|
138
|
+
* @param {string} workingDir - The directory where we're working (for NodePackageImporter).
|
|
139
|
+
* @return {object[]} Array of esbuild plugins for handling CSS/SCSS.
|
|
140
|
+
*/
|
|
141
|
+
function createStyleBundlingPlugins( workingDir ) {
|
|
142
|
+
const sassOptions = getSassOptions( workingDir );
|
|
143
|
+
return [
|
|
144
|
+
// Handle CSS modules (.module.css and .module.scss)
|
|
145
|
+
sassPlugin( {
|
|
146
|
+
embedded: true,
|
|
147
|
+
filter: /\.module\.(css|scss)$/,
|
|
148
|
+
transform: postcssModules( {
|
|
149
|
+
generateScopedName: '[name]__[local]__[hash:base64:5]',
|
|
150
|
+
} ),
|
|
151
|
+
type: 'style',
|
|
152
|
+
...sassOptions,
|
|
117
153
|
} ),
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
} ),
|
|
129
|
-
];
|
|
154
|
+
// Handle regular CSS/SCSS files
|
|
155
|
+
// Note: .module.css and .module.scss already handled by plugin above
|
|
156
|
+
sassPlugin( {
|
|
157
|
+
embedded: true,
|
|
158
|
+
filter: /\.(css|scss)$/,
|
|
159
|
+
type: 'style',
|
|
160
|
+
...sassOptions,
|
|
161
|
+
} ),
|
|
162
|
+
];
|
|
163
|
+
}
|
|
130
164
|
|
|
131
165
|
/**
|
|
132
166
|
* Normalize path separators for cross-platform compatibility.
|
|
@@ -193,56 +227,36 @@ function transformPhpContent( content, transforms ) {
|
|
|
193
227
|
function momentTimezoneAliasPlugin() {
|
|
194
228
|
return {
|
|
195
229
|
name: 'moment-timezone-alias',
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
// Cached paths - resolved lazily on first use
|
|
201
|
-
let preBuiltBundlePath;
|
|
202
|
-
let momentTimezoneUtilsPath;
|
|
203
|
-
const resolvePaths = () => {
|
|
204
|
-
if ( preBuiltBundlePath ) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
preBuiltBundlePath = require.resolve(
|
|
208
|
-
'moment-timezone/builds/moment-timezone-with-data-1970-2030'
|
|
209
|
-
);
|
|
210
|
-
momentTimezoneUtilsPath = require.resolve(
|
|
211
|
-
'moment-timezone/moment-timezone-utils.js'
|
|
212
|
-
);
|
|
213
|
-
};
|
|
230
|
+
setup( build ) {
|
|
231
|
+
// Alias path that esbuild will resolve
|
|
232
|
+
const aliasPath =
|
|
233
|
+
'moment-timezone/builds/moment-timezone-with-data-1970-2030.js';
|
|
214
234
|
|
|
215
235
|
// Redirect main moment-timezone files to pre-built bundle
|
|
216
236
|
build.onResolve(
|
|
217
|
-
{ filter: /^moment-timezone\/moment-timezone$/ },
|
|
218
|
-
() =>
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
// For utils, we need to load it but ensure it works with the pre-built bundle.
|
|
225
|
-
// The utils file tries to require('./') which would load index.js.
|
|
226
|
-
// We need to make sure it gets the pre-built bundle instead.
|
|
227
|
-
build.onResolve(
|
|
228
|
-
{ filter: /^moment-timezone\/moment-timezone-utils$/ },
|
|
229
|
-
() => {
|
|
230
|
-
resolvePaths();
|
|
231
|
-
return { path: momentTimezoneUtilsPath };
|
|
232
|
-
}
|
|
237
|
+
{ filter: /^moment-timezone\/moment-timezone\.js$/ },
|
|
238
|
+
( { importer, resolveDir, kind } ) =>
|
|
239
|
+
build.resolve( aliasPath, {
|
|
240
|
+
importer,
|
|
241
|
+
resolveDir,
|
|
242
|
+
kind,
|
|
243
|
+
} )
|
|
233
244
|
);
|
|
234
245
|
|
|
235
246
|
// Intercept the require('./') call inside moment-timezone-utils
|
|
236
247
|
// and redirect it to the pre-built bundle.
|
|
237
|
-
build.onResolve(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
248
|
+
build.onResolve(
|
|
249
|
+
{ filter: /^\.\/$/ },
|
|
250
|
+
( { importer, resolveDir, kind } ) => {
|
|
251
|
+
if ( importer.includes( 'moment-timezone-utils' ) ) {
|
|
252
|
+
return build.resolve( aliasPath, {
|
|
253
|
+
importer,
|
|
254
|
+
resolveDir,
|
|
255
|
+
kind,
|
|
256
|
+
} );
|
|
257
|
+
}
|
|
244
258
|
}
|
|
245
|
-
|
|
259
|
+
);
|
|
246
260
|
},
|
|
247
261
|
};
|
|
248
262
|
}
|
|
@@ -1092,7 +1106,7 @@ async function transpilePackage( packageName ) {
|
|
|
1092
1106
|
const plugins = [
|
|
1093
1107
|
needsEmotionPlugin && emotionPlugin,
|
|
1094
1108
|
externalizeAllExceptCssPlugin,
|
|
1095
|
-
...
|
|
1109
|
+
...createStyleBundlingPlugins( packageDir ),
|
|
1096
1110
|
].filter( Boolean );
|
|
1097
1111
|
|
|
1098
1112
|
if ( packageJson.main ) {
|
|
@@ -1226,10 +1240,7 @@ async function compileStyles( packageName ) {
|
|
|
1226
1240
|
plugins: [
|
|
1227
1241
|
sassPlugin( {
|
|
1228
1242
|
embedded: true,
|
|
1229
|
-
|
|
1230
|
-
'node_modules',
|
|
1231
|
-
path.join( PACKAGES_DIR, 'base-styles' ),
|
|
1232
|
-
],
|
|
1243
|
+
...getSassOptions( packageDir ),
|
|
1233
1244
|
async transform( source ) {
|
|
1234
1245
|
// Process with autoprefixer for LTR version
|
|
1235
1246
|
const ltrResult = await postcss( [
|
|
@@ -1414,7 +1425,7 @@ async function buildRoute( routeName ) {
|
|
|
1414
1425
|
[],
|
|
1415
1426
|
true // Generate asset file for minified build
|
|
1416
1427
|
),
|
|
1417
|
-
...
|
|
1428
|
+
...createStyleBundlingPlugins( routeDir ),
|
|
1418
1429
|
],
|
|
1419
1430
|
} ),
|
|
1420
1431
|
esbuild.build( {
|
|
@@ -1432,7 +1443,7 @@ async function buildRoute( routeName ) {
|
|
|
1432
1443
|
[],
|
|
1433
1444
|
false // Skip asset file for non-minified build
|
|
1434
1445
|
),
|
|
1435
|
-
...
|
|
1446
|
+
...createStyleBundlingPlugins( routeDir ),
|
|
1436
1447
|
],
|
|
1437
1448
|
} ),
|
|
1438
1449
|
] );
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/build",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.v.0+500f87dd8",
|
|
4
4
|
"description": "Build tool for WordPress plugins.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"moment-timezone": "^0.5.40",
|
|
49
49
|
"postcss": "8.4.38",
|
|
50
50
|
"postcss-modules": "6.0.1",
|
|
51
|
-
"rtlcss": "4.3.0"
|
|
51
|
+
"rtlcss": "4.3.0",
|
|
52
|
+
"sass-embedded": "^1.97.2"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@types/node": "^20.17.10"
|
|
@@ -76,5 +77,5 @@
|
|
|
76
77
|
"publishConfig": {
|
|
77
78
|
"access": "public"
|
|
78
79
|
},
|
|
79
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "ca0db0ee8ac2116cd307650136027d26d0cdd9bd"
|
|
80
81
|
}
|