@10up/build 1.0.0-alpha.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/README.md +508 -0
- package/bin/10up-build.js +11 -0
- package/config/postcss.config.js +36 -0
- package/dist/build.d.ts +11 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +315 -0
- package/dist/build.js.map +1 -0
- package/dist/cli.d.ts +8 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +122 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +103 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +230 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/block-json.d.ts +18 -0
- package/dist/plugins/block-json.d.ts.map +1 -0
- package/dist/plugins/block-json.js +172 -0
- package/dist/plugins/block-json.js.map +1 -0
- package/dist/plugins/copy-assets.d.ts +15 -0
- package/dist/plugins/copy-assets.d.ts.map +1 -0
- package/dist/plugins/copy-assets.js +62 -0
- package/dist/plugins/copy-assets.js.map +1 -0
- package/dist/plugins/sass-plugin.d.ts +17 -0
- package/dist/plugins/sass-plugin.d.ts.map +1 -0
- package/dist/plugins/sass-plugin.js +163 -0
- package/dist/plugins/sass-plugin.js.map +1 -0
- package/dist/plugins/wp-dependency-extraction.d.ts +27 -0
- package/dist/plugins/wp-dependency-extraction.d.ts.map +1 -0
- package/dist/plugins/wp-dependency-extraction.js +306 -0
- package/dist/plugins/wp-dependency-extraction.js.map +1 -0
- package/dist/types.d.ts +540 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/entry-detection.d.ts +13 -0
- package/dist/utils/entry-detection.d.ts.map +1 -0
- package/dist/utils/entry-detection.js +218 -0
- package/dist/utils/entry-detection.js.map +1 -0
- package/dist/utils/externals.d.ts +62 -0
- package/dist/utils/externals.d.ts.map +1 -0
- package/dist/utils/externals.js +152 -0
- package/dist/utils/externals.js.map +1 -0
- package/dist/utils/paths.d.ts +40 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +70 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/watch.d.ts +13 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.js +214 -0
- package/dist/watch.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point detection for WordPress blocks and build files
|
|
3
|
+
*/
|
|
4
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
5
|
+
import { dirname, extname, join, resolve } from 'node:path';
|
|
6
|
+
import fastGlob from 'fast-glob';
|
|
7
|
+
const glob = fastGlob.sync;
|
|
8
|
+
import { fromProjectRoot, normalizePath } from './paths.js';
|
|
9
|
+
/**
|
|
10
|
+
* Asset keys from block.json for scripts
|
|
11
|
+
*/
|
|
12
|
+
const JS_ASSET_KEYS = ['script', 'editorScript', 'viewScript'];
|
|
13
|
+
/**
|
|
14
|
+
* Asset keys from block.json for script modules
|
|
15
|
+
*/
|
|
16
|
+
const MODULE_ASSET_KEYS = ['scriptModule', 'viewScriptModule'];
|
|
17
|
+
/**
|
|
18
|
+
* Asset keys from block.json for styles
|
|
19
|
+
*/
|
|
20
|
+
const CSS_ASSET_KEYS = ['style', 'editorStyle', 'viewStyle'];
|
|
21
|
+
/**
|
|
22
|
+
* Detect all entry points for the build
|
|
23
|
+
*/
|
|
24
|
+
export async function detectEntries(config) {
|
|
25
|
+
const entries = {
|
|
26
|
+
scripts: {},
|
|
27
|
+
modules: {},
|
|
28
|
+
styles: {},
|
|
29
|
+
};
|
|
30
|
+
// 1. Load entries from buildfiles.config.js or config.entry
|
|
31
|
+
const buildFileEntries = await loadBuildFileEntries(config);
|
|
32
|
+
Object.assign(entries.scripts, buildFileEntries.scripts);
|
|
33
|
+
Object.assign(entries.styles, buildFileEntries.styles);
|
|
34
|
+
// 2. Load module entries from config.moduleEntry
|
|
35
|
+
if (config.moduleEntry && Object.keys(config.moduleEntry).length > 0) {
|
|
36
|
+
Object.assign(entries.modules, filterExistingEntries(config.moduleEntry));
|
|
37
|
+
}
|
|
38
|
+
// 3. Detect block.json entries if useBlockAssets is enabled
|
|
39
|
+
if (config.useBlockAssets) {
|
|
40
|
+
const blockEntries = detectBlockEntries(config);
|
|
41
|
+
Object.assign(entries.scripts, blockEntries.scripts);
|
|
42
|
+
Object.assign(entries.modules, blockEntries.modules);
|
|
43
|
+
Object.assign(entries.styles, blockEntries.styles);
|
|
44
|
+
}
|
|
45
|
+
return entries;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Load entries from buildfiles.config.js or config.entry
|
|
49
|
+
*/
|
|
50
|
+
async function loadBuildFileEntries(config) {
|
|
51
|
+
const result = {
|
|
52
|
+
scripts: {},
|
|
53
|
+
styles: {},
|
|
54
|
+
};
|
|
55
|
+
// Try buildfiles.config.js first
|
|
56
|
+
const buildFilesConfigPath = fromProjectRoot('buildfiles.config.js');
|
|
57
|
+
let entries = {};
|
|
58
|
+
if (existsSync(buildFilesConfigPath)) {
|
|
59
|
+
try {
|
|
60
|
+
const buildFilesModule = await import(`file://${buildFilesConfigPath}`);
|
|
61
|
+
entries = buildFilesModule.default || buildFilesModule;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.warn('Warning: Could not load buildfiles.config.js:', error instanceof Error ? error.message : error);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (config.entry && Object.keys(config.entry).length > 0) {
|
|
68
|
+
// Use config.entry as fallback
|
|
69
|
+
entries = config.entry;
|
|
70
|
+
}
|
|
71
|
+
// Separate JS and CSS entries, adding js/ and css/ prefixes for output organization
|
|
72
|
+
for (const [name, filePath] of Object.entries(entries)) {
|
|
73
|
+
const resolvedPath = fromProjectRoot(filePath);
|
|
74
|
+
if (!existsSync(resolvedPath)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const ext = extname(filePath).toLowerCase();
|
|
78
|
+
if (['.css', '.scss', '.sass'].includes(ext)) {
|
|
79
|
+
// CSS entries go to css/ subdirectory
|
|
80
|
+
result.styles[`css/${name}`] = resolvedPath;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// JS entries go to js/ subdirectory
|
|
84
|
+
result.scripts[`js/${name}`] = resolvedPath;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Filter entries to only include existing files, adding js/ prefix for output organization
|
|
91
|
+
*/
|
|
92
|
+
function filterExistingEntries(entries) {
|
|
93
|
+
const result = {};
|
|
94
|
+
for (const [name, filePath] of Object.entries(entries)) {
|
|
95
|
+
const resolvedPath = fromProjectRoot(filePath);
|
|
96
|
+
if (existsSync(resolvedPath)) {
|
|
97
|
+
// Add js/ prefix for module entries
|
|
98
|
+
result[`js/${name}`] = resolvedPath;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Detect entries from block.json files
|
|
105
|
+
*/
|
|
106
|
+
function detectBlockEntries(config) {
|
|
107
|
+
const result = { scripts: {}, modules: {}, styles: {} };
|
|
108
|
+
const blocksDir = resolve(process.cwd(), config.paths.blocksDir);
|
|
109
|
+
if (!existsSync(blocksDir)) {
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
// Find all block.json files
|
|
113
|
+
const blockMetadataFiles = glob(normalizePath(`${blocksDir}/**/block.json`), {
|
|
114
|
+
absolute: true,
|
|
115
|
+
});
|
|
116
|
+
for (const blockMetadataFile of blockMetadataFiles) {
|
|
117
|
+
try {
|
|
118
|
+
const metadata = JSON.parse(readFileSync(blockMetadataFile, 'utf8'));
|
|
119
|
+
const blockDir = dirname(blockMetadataFile);
|
|
120
|
+
// Process script assets
|
|
121
|
+
for (const key of JS_ASSET_KEYS) {
|
|
122
|
+
const asset = metadata[key];
|
|
123
|
+
if (asset) {
|
|
124
|
+
const entries = processAssetField(asset, blockDir, blocksDir, false);
|
|
125
|
+
Object.assign(result.scripts, entries);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Process script module assets
|
|
129
|
+
for (const key of MODULE_ASSET_KEYS) {
|
|
130
|
+
const asset = metadata[key];
|
|
131
|
+
if (asset) {
|
|
132
|
+
const entries = processAssetField(asset, blockDir, blocksDir, false);
|
|
133
|
+
Object.assign(result.modules, entries);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Process style assets
|
|
137
|
+
for (const key of CSS_ASSET_KEYS) {
|
|
138
|
+
const asset = metadata[key];
|
|
139
|
+
if (asset) {
|
|
140
|
+
const entries = processAssetField(asset, blockDir, blocksDir, true);
|
|
141
|
+
Object.assign(result.styles, entries);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
// Skip malformed block.json files
|
|
147
|
+
console.warn(`Warning: Could not parse ${blockMetadataFile}:`, error instanceof Error ? error.message : error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Process an asset field from block.json
|
|
154
|
+
*/
|
|
155
|
+
function processAssetField(asset, blockDir, blocksDir, isStyle) {
|
|
156
|
+
const result = {};
|
|
157
|
+
const assets = Array.isArray(asset) ? asset : [asset];
|
|
158
|
+
for (const rawFilepath of assets) {
|
|
159
|
+
// Only process file: prefixed paths
|
|
160
|
+
if (!rawFilepath || !rawFilepath.startsWith('file:')) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const relativePath = rawFilepath.replace('file:', '');
|
|
164
|
+
const targetPath = join(blockDir, relativePath);
|
|
165
|
+
// Generate entry name from path
|
|
166
|
+
const entryName = targetPath
|
|
167
|
+
.replace(extname(targetPath), '')
|
|
168
|
+
.replace(blocksDir, '')
|
|
169
|
+
.replace(/^[/\\]/, '');
|
|
170
|
+
// Find the actual source file (might be .ts, .tsx, .scss, etc.)
|
|
171
|
+
const sourceFile = findSourceFile(targetPath, isStyle);
|
|
172
|
+
if (sourceFile) {
|
|
173
|
+
result[`blocks/${normalizePath(entryName)}`] = sourceFile;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Find the actual source file for a target path
|
|
180
|
+
*/
|
|
181
|
+
function findSourceFile(targetPath, isStyle) {
|
|
182
|
+
const dir = dirname(targetPath);
|
|
183
|
+
const baseName = targetPath
|
|
184
|
+
.replace(extname(targetPath), '')
|
|
185
|
+
.replace(dir, '')
|
|
186
|
+
.replace(/^[/\\]/, '');
|
|
187
|
+
const extensions = isStyle ? ['.css', '.scss', '.sass'] : ['.js', '.jsx', '.ts', '.tsx'];
|
|
188
|
+
for (const ext of extensions) {
|
|
189
|
+
const sourcePath = join(dir, `${baseName}${ext}`);
|
|
190
|
+
if (existsSync(sourcePath)) {
|
|
191
|
+
return sourcePath;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Try the exact path
|
|
195
|
+
if (existsSync(targetPath)) {
|
|
196
|
+
return targetPath;
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get block-specific style entries (for loadBlockSpecificStyles option)
|
|
202
|
+
*/
|
|
203
|
+
export function getBlockSpecificStyles(config) {
|
|
204
|
+
const result = {};
|
|
205
|
+
const stylesDir = resolve(process.cwd(), config.paths.blocksStyles);
|
|
206
|
+
if (!existsSync(stylesDir)) {
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
const stylesheets = glob(normalizePath(`${stylesDir}/**/*.{css,scss,sass}`), {
|
|
210
|
+
absolute: true,
|
|
211
|
+
});
|
|
212
|
+
for (const filePath of stylesheets) {
|
|
213
|
+
const blockName = filePath.replace(`${stylesDir}/`, '').replace(extname(filePath), '');
|
|
214
|
+
result[`autoenqueue/${normalizePath(blockName)}`] = filePath;
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=entry-detection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-detection.js","sourceRoot":"","sources":["../../src/utils/entry-detection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG5D;;GAEG;AACH,MAAM,aAAa,GAA4B,CAAC,QAAQ,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;AAExF;;GAEG;AACH,MAAM,iBAAiB,GAA4B,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;AAExF;;GAEG;AACH,MAAM,cAAc,GAA4B,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;AAEtF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAmB;IACtD,MAAM,OAAO,GAAoB;QAChC,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,EAAE;KACV,CAAC;IAEF,4DAA4D;IAC5D,MAAM,gBAAgB,GAAG,MAAM,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC5D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzD,MAAM,CAAC,MAAM,CAAC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ag in package.json
|
|
5
|
+
* instead of maintaining a hardcoded list.
|
|
6
|
+
*/
|
|
7
|
+
import type { BuildConfig, ExternalResolution } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Vendor externals - these don't have wpScript flag
|
|
10
|
+
* so we maintain them as a hardcoded list
|
|
11
|
+
*/
|
|
12
|
+
export declare const vendorExternals: Record<string, ExternalResolution>;
|
|
13
|
+
/**
|
|
14
|
+
* Result of checking a WordPress package
|
|
15
|
+
*/
|
|
16
|
+
interface WpPackageCheckResult {
|
|
17
|
+
/** Whether the package should be externalized */
|
|
18
|
+
isExternal: boolean;
|
|
19
|
+
/** Whether the package was found/installed locally */
|
|
20
|
+
isInstalled: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if a @wordpress/* package has wpScript: true
|
|
24
|
+
* Returns:
|
|
25
|
+
* - isExternal: true if package should be externalized (wpScript: true or not installed)
|
|
26
|
+
* - isInstalled: true if package was found in node_modules
|
|
27
|
+
*
|
|
28
|
+
* This ensures we externalize all @wordpress/* imports, even if
|
|
29
|
+
* the package isn't a direct dependency of the project.
|
|
30
|
+
*
|
|
31
|
+
* @param packageName - The @wordpress/* package name to check
|
|
32
|
+
* @returns Object with isExternal and isInstalled flags
|
|
33
|
+
*/
|
|
34
|
+
export declare function isWpScriptPackage(packageName: string): WpPackageCheckResult;
|
|
35
|
+
/**
|
|
36
|
+
* Convert @wordpress/* package name to WP script handle
|
|
37
|
+
* @example '@wordpress/blocks' -> 'wp-blocks'
|
|
38
|
+
*/
|
|
39
|
+
export declare function wpPackageToHandle(packageName: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Convert @wordpress/* package name to global variable path
|
|
42
|
+
* @example '@wordpress/blocks' -> 'wp.blocks'
|
|
43
|
+
*/
|
|
44
|
+
export declare function wpPackageToGlobal(packageName: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Resolve external configuration for a package
|
|
47
|
+
*
|
|
48
|
+
* @param packageName - The package name to resolve
|
|
49
|
+
* @param config - Build configuration with external namespaces
|
|
50
|
+
* @returns External resolution with global and handle, or null if not external
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveExternal(packageName: string, config?: Partial<BuildConfig>): ExternalResolution | null;
|
|
53
|
+
/**
|
|
54
|
+
* Get all external patterns for esbuild
|
|
55
|
+
*/
|
|
56
|
+
export declare function getExternalPatterns(config?: Partial<BuildConfig>): string[];
|
|
57
|
+
/**
|
|
58
|
+
* Create esbuild global mappings for externals
|
|
59
|
+
*/
|
|
60
|
+
export declare function createGlobalMappings(dependencies: Set<string>, config?: Partial<BuildConfig>): Record<string, string>;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=externals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"externals.d.ts","sourceRoot":"","sources":["../../src/utils/externals.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAInE;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAS9D,CAAC;AAOF;;GAEG;AACH,UAAU,oBAAoB;IAC7B,iDAAiD;IACjD,UAAU,EAAE,OAAO,CAAC;IACpB,sDAAsD;IACtD,WAAW,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,oBAAoB,CAqB3E;AASD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC9B,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM,GAC/B,kBAAkB,GAAG,IAAI,CAkC3B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,MAAM,EAAE,CAe/E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CACnC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,EACzB,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM,GAC/B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWxB"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress and vendor externals handling
|
|
3
|
+
*
|
|
4
|
+
* Uses dynamic detection via wpScript flag in package.json
|
|
5
|
+
* instead of maintaining a hardcoded list.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
/**
|
|
11
|
+
* Vendor externals - these don't have wpScript flag
|
|
12
|
+
* so we maintain them as a hardcoded list
|
|
13
|
+
*/
|
|
14
|
+
export const vendorExternals = {
|
|
15
|
+
react: { global: 'React', handle: 'react' },
|
|
16
|
+
'react-dom': { global: 'ReactDOM', handle: 'react-dom' },
|
|
17
|
+
'react-dom/client': { global: 'ReactDOM', handle: 'react-dom' },
|
|
18
|
+
'react/jsx-runtime': { global: 'ReactJSXRuntime', handle: 'react-jsx-runtime' },
|
|
19
|
+
lodash: { global: 'lodash', handle: 'lodash' },
|
|
20
|
+
'lodash-es': { global: 'lodash', handle: 'lodash' },
|
|
21
|
+
moment: { global: 'moment', handle: 'moment' },
|
|
22
|
+
jquery: { global: 'jQuery', handle: 'jquery' },
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Cache for package.json wpScript lookups
|
|
26
|
+
*/
|
|
27
|
+
const wpScriptCache = new Map();
|
|
28
|
+
/**
|
|
29
|
+
* Check if a @wordpress/* package has wpScript: true
|
|
30
|
+
* Returns:
|
|
31
|
+
* - isExternal: true if package should be externalized (wpScript: true or not installed)
|
|
32
|
+
* - isInstalled: true if package was found in node_modules
|
|
33
|
+
*
|
|
34
|
+
* This ensures we externalize all @wordpress/* imports, even if
|
|
35
|
+
* the package isn't a direct dependency of the project.
|
|
36
|
+
*
|
|
37
|
+
* @param packageName - The @wordpress/* package name to check
|
|
38
|
+
* @returns Object with isExternal and isInstalled flags
|
|
39
|
+
*/
|
|
40
|
+
export function isWpScriptPackage(packageName) {
|
|
41
|
+
// Check cache first
|
|
42
|
+
const cached = wpScriptCache.get(packageName);
|
|
43
|
+
if (cached !== undefined) {
|
|
44
|
+
// For cached results, we can't determine isInstalled from boolean
|
|
45
|
+
// So we need to try resolving again
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const pkgJsonPath = require.resolve(`${packageName}/package.json`);
|
|
49
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));
|
|
50
|
+
const hasWpScript = pkgJson.wpScript === true;
|
|
51
|
+
wpScriptCache.set(packageName, hasWpScript);
|
|
52
|
+
return { isExternal: hasWpScript, isInstalled: true };
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Package not installed - assume it should be externalized
|
|
56
|
+
// since all @wordpress/* packages with wpScript=true are
|
|
57
|
+
// available as WordPress globals at runtime
|
|
58
|
+
wpScriptCache.set(packageName, true);
|
|
59
|
+
return { isExternal: true, isInstalled: false };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Convert a string to camelCase
|
|
64
|
+
*/
|
|
65
|
+
function camelCase(str) {
|
|
66
|
+
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Convert @wordpress/* package name to WP script handle
|
|
70
|
+
* @example '@wordpress/blocks' -> 'wp-blocks'
|
|
71
|
+
*/
|
|
72
|
+
export function wpPackageToHandle(packageName) {
|
|
73
|
+
return packageName.replace('@wordpress/', 'wp-');
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert @wordpress/* package name to global variable path
|
|
77
|
+
* @example '@wordpress/blocks' -> 'wp.blocks'
|
|
78
|
+
*/
|
|
79
|
+
export function wpPackageToGlobal(packageName) {
|
|
80
|
+
const name = packageName.replace('@wordpress/', '');
|
|
81
|
+
return `wp.${camelCase(name)}`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resolve external configuration for a package
|
|
85
|
+
*
|
|
86
|
+
* @param packageName - The package name to resolve
|
|
87
|
+
* @param config - Build configuration with external namespaces
|
|
88
|
+
* @returns External resolution with global and handle, or null if not external
|
|
89
|
+
*/
|
|
90
|
+
export function resolveExternal(packageName, config = {}) {
|
|
91
|
+
// 1. Check @wordpress/* packages (read wpScript from package.json)
|
|
92
|
+
if (packageName.startsWith('@wordpress/')) {
|
|
93
|
+
const checkResult = isWpScriptPackage(packageName);
|
|
94
|
+
if (checkResult.isExternal) {
|
|
95
|
+
return {
|
|
96
|
+
global: wpPackageToGlobal(packageName),
|
|
97
|
+
handle: wpPackageToHandle(packageName),
|
|
98
|
+
// Include installation status for warning purposes
|
|
99
|
+
_isInstalled: checkResult.isInstalled,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// Not a wpScript package, don't externalize
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
// 2. Check custom namespaces from config
|
|
106
|
+
const externalNamespaces = config.externalNamespaces || {};
|
|
107
|
+
for (const [namespace, mapping] of Object.entries(externalNamespaces)) {
|
|
108
|
+
if (packageName.startsWith(`${namespace}/`)) {
|
|
109
|
+
const name = packageName.replace(`${namespace}/`, '');
|
|
110
|
+
return {
|
|
111
|
+
global: `${mapping.global}.${camelCase(name)}`,
|
|
112
|
+
handle: `${mapping.handlePrefix}-${name}`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// 3. Check vendor externals
|
|
117
|
+
if (vendorExternals[packageName]) {
|
|
118
|
+
return vendorExternals[packageName];
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get all external patterns for esbuild
|
|
124
|
+
*/
|
|
125
|
+
export function getExternalPatterns(config = {}) {
|
|
126
|
+
const patterns = [
|
|
127
|
+
// Vendor externals
|
|
128
|
+
...Object.keys(vendorExternals),
|
|
129
|
+
// WordPress packages (will be filtered by wpScript check at resolve time)
|
|
130
|
+
'@wordpress/*',
|
|
131
|
+
];
|
|
132
|
+
// Add custom namespace patterns
|
|
133
|
+
const externalNamespaces = config.externalNamespaces || {};
|
|
134
|
+
for (const namespace of Object.keys(externalNamespaces)) {
|
|
135
|
+
patterns.push(`${namespace}/*`);
|
|
136
|
+
}
|
|
137
|
+
return patterns;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Create esbuild global mappings for externals
|
|
141
|
+
*/
|
|
142
|
+
export function createGlobalMappings(dependencies, config = {}) {
|
|
143
|
+
const mappings = {};
|
|
144
|
+
for (const dep of dependencies) {
|
|
145
|
+
const external = resolveExternal(dep, config);
|
|
146
|
+
if (external) {
|
|
147
|
+
mappings[dep] = external.global;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return mappings;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=externals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"externals.js","sourceRoot":"","sources":["../../src/utils/externals.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAuC;IAClE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO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IAE5C,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC9C,IAAI,QAAQ,EAAE,CAAC;YACd,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;QACjC,CAAC;IACF,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path utilities for 10up-build
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get the project root directory (where package.json is)
|
|
6
|
+
*/
|
|
7
|
+
export declare function getProjectRoot(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve a path from the project root
|
|
10
|
+
*/
|
|
11
|
+
export declare function fromProjectRoot(relativePath: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve a path from the package root (where this package is installed)
|
|
14
|
+
*/
|
|
15
|
+
export declare function fromPackageRoot(relativePath: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a file exists in the project
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasProjectFile(relativePath: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a file exists
|
|
22
|
+
*/
|
|
23
|
+
export declare function fileExists(absolutePath: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Get a content-based hash of a file
|
|
26
|
+
*/
|
|
27
|
+
export declare function getFileContentHash(filePath: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get a content-based hash from a string or buffer
|
|
30
|
+
*/
|
|
31
|
+
export declare function getContentHash(content: string | Buffer): string;
|
|
32
|
+
/**
|
|
33
|
+
* Normalize a path to use forward slashes (for glob patterns)
|
|
34
|
+
*/
|
|
35
|
+
export declare function normalizePath(filePath: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Remove dist folder prefix from a path
|
|
38
|
+
*/
|
|
39
|
+
export declare function removeDistFolder(file: string): string;
|
|
40
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE/D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path utilities for 10up-build
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { resolve, dirname } from 'node:path';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
/**
|
|
11
|
+
* Get the project root directory (where package.json is)
|
|
12
|
+
*/
|
|
13
|
+
export function getProjectRoot() {
|
|
14
|
+
return process.cwd();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a path from the project root
|
|
18
|
+
*/
|
|
19
|
+
export function fromProjectRoot(relativePath) {
|
|
20
|
+
return resolve(getProjectRoot(), relativePath);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a path from the package root (where this package is installed)
|
|
24
|
+
*/
|
|
25
|
+
export function fromPackageRoot(relativePath) {
|
|
26
|
+
return resolve(__dirname, '..', '..', relativePath);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if a file exists in the project
|
|
30
|
+
*/
|
|
31
|
+
export function hasProjectFile(relativePath) {
|
|
32
|
+
return existsSync(fromProjectRoot(relativePath));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if a file exists
|
|
36
|
+
*/
|
|
37
|
+
export function fileExists(absolutePath) {
|
|
38
|
+
return existsSync(absolutePath);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get a content-based hash of a file
|
|
42
|
+
*/
|
|
43
|
+
export function getFileContentHash(filePath) {
|
|
44
|
+
try {
|
|
45
|
+
const content = readFileSync(filePath);
|
|
46
|
+
return createHash('sha256').update(content).digest('hex').slice(0, 8);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get a content-based hash from a string or buffer
|
|
54
|
+
*/
|
|
55
|
+
export function getContentHash(content) {
|
|
56
|
+
return createHash('sha256').update(content).digest('hex').slice(0, 20);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Normalize a path to use forward slashes (for glob patterns)
|
|
60
|
+
*/
|
|
61
|
+
export function normalizePath(filePath) {
|
|
62
|
+
return filePath.replace(/\\/g, '/');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Remove dist folder prefix from a path
|
|
66
|
+
*/
|
|
67
|
+
export function removeDistFolder(file) {
|
|
68
|
+
return file.replace(/(^\.\/dist\/)|^dist\//, '');
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC;;GAEG;AACH,MAAM,UAAU,cAAc;IAC7B,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,YAAoB;IACnD,OAAO,OAAO,CAAC,cAAc,EAAE,EAAE,YAAY,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,YAAoB;IACnD,OAAO,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,YAAoB;IAClD,OAAO,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,YAAoB;IAC9C,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IAClD,IAAI,CAAC;QACJ,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QACvC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACvE,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,CAAC;IACX,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,OAAwB;IACtD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC7C,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/watch.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watch mode with React Fast Refresh support
|
|
3
|
+
*/
|
|
4
|
+
import type { WatchOptions } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Notify clients of rebuild (exported for future use)
|
|
7
|
+
*/
|
|
8
|
+
export declare function notifyRebuild(success: boolean): void;
|
|
9
|
+
/**
|
|
10
|
+
* Watch mode entry point
|
|
11
|
+
*/
|
|
12
|
+
export declare function watch(options?: WatchOptions): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=watch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,YAAY,CAAC;AAiB5D;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAKpD;AAmHD;;GAEG;AACH,wBAAsB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6FrE"}
|