@atomicsmash/compiler 4.0.0-beta.3 → 4.0.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/dist/BlocksPlugin.js +3 -3
- package/dist/cli.js +5 -7
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +20 -9
- package/dist/getBlocksAssetsEntryPoints.d.ts.map +1 -1
- package/dist/getBlocksAssetsEntryPoints.js +28 -30
- package/package.json +3 -3
package/dist/BlocksPlugin.js
CHANGED
|
@@ -21,7 +21,7 @@ export class BlocksPlugin {
|
|
|
21
21
|
const blockJsonFiles = Object.keys(assets).filter((asset) => asset.endsWith("block.json"));
|
|
22
22
|
const PHPFiles = await glob([
|
|
23
23
|
...blockJsonFiles.map((blockJsonPath) => {
|
|
24
|
-
return
|
|
24
|
+
return resolve(`${this.srcFolder}${pathSeparator}${blockJsonPath}`, "..", `**${pathSeparator}*.php`);
|
|
25
25
|
}),
|
|
26
26
|
]);
|
|
27
27
|
await Promise.all(PHPFiles.map(async (file) => {
|
|
@@ -68,14 +68,14 @@ export class BlocksPlugin {
|
|
|
68
68
|
.replace(extname(srcFilePath), "")
|
|
69
69
|
.split(".");
|
|
70
70
|
const hashedAsset = Object.keys(compilation.assets).find((asset) => {
|
|
71
|
-
return (asset.startsWith(`${blockName}${pathSeparator}${fileName}`) && !asset.endsWith(".php"));
|
|
71
|
+
return (asset.startsWith(`${blockName}${pathSeparator}${fileName ?? ""}`) && !asset.endsWith(".php"));
|
|
72
72
|
});
|
|
73
73
|
if (hashedAsset &&
|
|
74
74
|
(!contentHash || !hashedAsset.includes(contentHash))) {
|
|
75
75
|
if (hashedAsset in wordpressAssets) {
|
|
76
76
|
await writeFile(`${compilation.outputOptions.path}${pathSeparator}${hashedAsset.replace(extname(hashedAsset), ".asset.php")}`, `<?php return ${printer(wordpressAssets[hashedAsset])};\n`, "utf-8");
|
|
77
77
|
}
|
|
78
|
-
const oldAssetFileLocation = `${compilation.outputOptions.path}${pathSeparator}${blockName}${pathSeparator}${fileName}.${contentHash}.asset.php`;
|
|
78
|
+
const oldAssetFileLocation = `${compilation.outputOptions.path}${pathSeparator}${blockName}${pathSeparator}${fileName ?? ""}.${contentHash ?? ""}.asset.php`;
|
|
79
79
|
if (contentHash && existsSync(oldAssetFileLocation)) {
|
|
80
80
|
await deleteFile(oldAssetFileLocation);
|
|
81
81
|
}
|
package/dist/cli.js
CHANGED
|
@@ -35,6 +35,7 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
35
35
|
string: true,
|
|
36
36
|
default: ["__TEMPLATE__"],
|
|
37
37
|
describe: "A comma separated list of the folder names of blocks to exclude from compilation. Requires experimental blocks support.",
|
|
38
|
+
deprecate: "Use folders which start with an underscore instead.",
|
|
38
39
|
},
|
|
39
40
|
})
|
|
40
41
|
.showHelpOnFail(false, "Specify --help for available options")
|
|
@@ -42,9 +43,6 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
42
43
|
// eslint-disable-next-line @typescript-eslint/naming-convention -- Experimental option.
|
|
43
44
|
const { experimentalBlocksSupport, ...compilerOptions } = argv;
|
|
44
45
|
const compiler = webpack(await defaultConfig({ ...compilerOptions }));
|
|
45
|
-
if (!compiler) {
|
|
46
|
-
throw new Error("Failed to initialise compiler.");
|
|
47
|
-
}
|
|
48
46
|
if (argv.watch) {
|
|
49
47
|
let i = 0;
|
|
50
48
|
console.log("Starting dev compiler.");
|
|
@@ -63,14 +61,14 @@ if (argv.watch) {
|
|
|
63
61
|
else if (stats && i > 0) {
|
|
64
62
|
const info = stats.toJson();
|
|
65
63
|
if (stats.hasErrors()) {
|
|
66
|
-
const errors = info.errors;
|
|
64
|
+
const errors = info.errors ?? [];
|
|
67
65
|
console.warn("The compiler produced the following errors: \n");
|
|
68
66
|
for (const error of errors) {
|
|
69
67
|
console.warn(error.message);
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
70
|
if (stats.hasWarnings()) {
|
|
73
|
-
const warnings = info.warnings;
|
|
71
|
+
const warnings = info.warnings ?? [];
|
|
74
72
|
console.warn("The compiler produced the following warnings: \n");
|
|
75
73
|
for (const warning of warnings) {
|
|
76
74
|
console.warn(warning.message);
|
|
@@ -103,7 +101,7 @@ else {
|
|
|
103
101
|
else if (stats) {
|
|
104
102
|
const info = stats.toJson();
|
|
105
103
|
if (stats.hasErrors()) {
|
|
106
|
-
const errors = info.errors;
|
|
104
|
+
const errors = info.errors ?? [];
|
|
107
105
|
console.warn("The compiler produced the following errors: \n");
|
|
108
106
|
for (const error of errors) {
|
|
109
107
|
console.warn(error.message);
|
|
@@ -111,7 +109,7 @@ else {
|
|
|
111
109
|
process.exitCode = 1;
|
|
112
110
|
}
|
|
113
111
|
if (stats.hasWarnings()) {
|
|
114
|
-
const warnings = info.warnings;
|
|
112
|
+
const warnings = info.warnings ?? [];
|
|
115
113
|
console.warn("The compiler produced the following warnings: \n");
|
|
116
114
|
for (const warning of warnings) {
|
|
117
115
|
console.warn(warning.message);
|
package/dist/config.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export declare function config(options: {
|
|
|
29
29
|
analyse?: boolean | undefined;
|
|
30
30
|
/**
|
|
31
31
|
* A comma separated list of the folder names of blocks to exclude from compilation. Requires experimental blocks support.
|
|
32
|
+
*
|
|
33
|
+
* @deprecated Use folders which start with an underscore instead.
|
|
32
34
|
*/
|
|
33
35
|
excludeBlocks?: string[] | undefined;
|
|
34
36
|
}): Promise<{
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAiB,QAAQ,EAAe,MAAM,SAAS,CAAC;AAUpE,OAAO,iCAAiC,MAAM,iDAAiD,CAAC;AAEhG,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAA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C/D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,wBAAsB,MAAM,CAAC,OAAO,EAAE;IACrC;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yCA2M4B,QAAQ;;;;;;;;;;;;;;;qCAeV,QAAQ;;;;;;;;;;sCAjQA,CAAC;;;;;;;;;;;;;;;;;;;;;;;GAycnC"}
|
package/dist/config.js
CHANGED
|
@@ -29,12 +29,12 @@ export async function config(options) {
|
|
|
29
29
|
const srcFolder = argv.in
|
|
30
30
|
? resolvePath(argv.in)
|
|
31
31
|
: smashConfig?.themePath
|
|
32
|
-
? resolvePath(join(smashConfig
|
|
32
|
+
? resolvePath(join(smashConfig.themePath, "src"))
|
|
33
33
|
: null;
|
|
34
34
|
const distFolder = argv.out
|
|
35
35
|
? resolvePath(argv.out)
|
|
36
36
|
: smashConfig?.themePath
|
|
37
|
-
? resolvePath(join(smashConfig
|
|
37
|
+
? resolvePath(join(smashConfig.themePath, smashConfig.assetsOutputFolder))
|
|
38
38
|
: null;
|
|
39
39
|
if (!srcFolder || !distFolder) {
|
|
40
40
|
throw new Error("Failed to get the in or out folders for the blocks. Please add a smash.config.ts file to your project with a themeName and a themePath.");
|
|
@@ -113,14 +113,18 @@ export async function config(options) {
|
|
|
113
113
|
entry: await glob([
|
|
114
114
|
// Parse all block json typescript files in the blocks folder.
|
|
115
115
|
`${srcFolder}/blocks/**/block.json.ts`,
|
|
116
|
-
// Parse all
|
|
117
|
-
`${srcFolder}/scripts
|
|
118
|
-
// Parse all
|
|
119
|
-
`${srcFolder}/styles
|
|
116
|
+
// Parse all children of the JS folder, as long as they are JS & TS files and not in a folder that starts with an underscore
|
|
117
|
+
`${srcFolder}/scripts/**/*.{js,ts,jsx,tsx}`,
|
|
118
|
+
// Parse all children of the CSS folder, as long as they are CSS files and not in a folder that starts with an underscore
|
|
119
|
+
`${srcFolder}/styles/**/*.css`,
|
|
120
120
|
// Parse all nested children of the CSS folder, as long as they are non-partial SCSS files
|
|
121
121
|
`${srcFolder}/styles/**/[^_]*.s[ac]ss`,
|
|
122
122
|
], {
|
|
123
|
-
ignore:
|
|
123
|
+
ignore: [
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- Support for a few more versions to allow migration
|
|
125
|
+
...argv.excludeBlocks.map((blockName) => `${srcFolder}/blocks/**/${blockName}/block.json.ts`),
|
|
126
|
+
"!**/_*/**", // Exclude any folder that starts with an underscore for all files
|
|
127
|
+
],
|
|
124
128
|
}).then(async (paths) => {
|
|
125
129
|
const { restOfPaths, entryPoints } = await getBlocksAssetsEntryPoints(paths, {}, srcFolder);
|
|
126
130
|
restOfPaths.forEach((path) => {
|
|
@@ -310,16 +314,20 @@ export async function config(options) {
|
|
|
310
314
|
}
|
|
311
315
|
if (entry.key === "assets.php" ||
|
|
312
316
|
entry.key === "wordpress-assets-info.php" ||
|
|
317
|
+
entry.key === "wordpress-assets-info.json" ||
|
|
313
318
|
entry.key.endsWith(".map") ||
|
|
314
319
|
entry.key.startsWith("fonts") ||
|
|
315
|
-
entry.key.startsWith("images")
|
|
320
|
+
entry.key.startsWith("images") ||
|
|
321
|
+
entry.key.endsWith(".scss.css") ||
|
|
322
|
+
entry.key.endsWith(".css.css")) {
|
|
316
323
|
return false;
|
|
317
324
|
}
|
|
318
325
|
if (entry.key === "spritemap.svg") {
|
|
319
326
|
entry.key = "icons/sprite.svg";
|
|
320
327
|
return entry;
|
|
321
328
|
}
|
|
322
|
-
if (entry.key.startsWith("icons/sprite") &&
|
|
329
|
+
if (entry.key.startsWith("icons/sprite") &&
|
|
330
|
+
entry.key.endsWith(".svg")) {
|
|
323
331
|
entry.key = "icons/sprite.svg";
|
|
324
332
|
return entry;
|
|
325
333
|
}
|
|
@@ -332,6 +340,9 @@ export async function config(options) {
|
|
|
332
340
|
if (entry.key.endsWith(".js")) {
|
|
333
341
|
entry.key = entry.key.slice(0, -3);
|
|
334
342
|
}
|
|
343
|
+
if (entry.key.endsWith(".css.css")) {
|
|
344
|
+
entry.key = entry.key.slice(0, -3);
|
|
345
|
+
}
|
|
335
346
|
return entry;
|
|
336
347
|
},
|
|
337
348
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBlocksAssetsEntryPoints.d.ts","sourceRoot":"","sources":["../src/getBlocksAssetsEntryPoints.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAK3C,wBAAsB,0BAA0B,CAC/C,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM;;;
|
|
1
|
+
{"version":3,"file":"getBlocksAssetsEntryPoints.d.ts","sourceRoot":"","sources":["../src/getBlocksAssetsEntryPoints.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAK3C,wBAAsB,0BAA0B,CAC/C,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM;;;GAgDjB"}
|
|
@@ -13,37 +13,35 @@ export async function getBlocksAssetsEntryPoints(paths, entryPoints, srcFolder)
|
|
|
13
13
|
...getBlockJsonScriptFields(blockJson),
|
|
14
14
|
...getBlockJsonStyleFields(blockJson),
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
const fileLocation = resolve(path, "../", value.slice(5));
|
|
22
|
-
const entryName = relative(srcFolder, fileLocation);
|
|
23
|
-
const type = extname(fileLocation);
|
|
24
|
-
let fileName = entryName;
|
|
25
|
-
switch (type) {
|
|
26
|
-
case ".ts":
|
|
27
|
-
fileName = fileName.replace(".ts", ".[contenthash].js");
|
|
28
|
-
break;
|
|
29
|
-
case ".tsx":
|
|
30
|
-
fileName = fileName.replace(".tsx", ".[contenthash].js");
|
|
31
|
-
break;
|
|
32
|
-
case ".js":
|
|
33
|
-
fileName = fileName.replace(".js", ".[contenthash].js");
|
|
34
|
-
break;
|
|
35
|
-
case ".css":
|
|
36
|
-
fileName = fileName.replace(".css", ".[contenthash].css");
|
|
37
|
-
break;
|
|
38
|
-
case ".scss":
|
|
39
|
-
fileName = fileName.replace(".scss", ".[contenthash].css");
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
entryPoints[entryName] = {
|
|
43
|
-
import: resolve(path, "../", value.slice(5)),
|
|
44
|
-
filename: fileName,
|
|
45
|
-
};
|
|
16
|
+
for (const value of Object.values(fields).flat()) {
|
|
17
|
+
if (!value.startsWith("file:")) {
|
|
18
|
+
continue;
|
|
46
19
|
}
|
|
20
|
+
const fileLocation = resolve(path, "../", value.slice(5));
|
|
21
|
+
const entryName = relative(srcFolder, fileLocation);
|
|
22
|
+
const type = extname(fileLocation);
|
|
23
|
+
let fileName = entryName;
|
|
24
|
+
switch (type) {
|
|
25
|
+
case ".ts":
|
|
26
|
+
fileName = fileName.replace(".ts", ".[contenthash].js");
|
|
27
|
+
break;
|
|
28
|
+
case ".tsx":
|
|
29
|
+
fileName = fileName.replace(".tsx", ".[contenthash].js");
|
|
30
|
+
break;
|
|
31
|
+
case ".js":
|
|
32
|
+
fileName = fileName.replace(".js", ".[contenthash].js");
|
|
33
|
+
break;
|
|
34
|
+
case ".css":
|
|
35
|
+
fileName = fileName.replace(".css", ".[contenthash].css");
|
|
36
|
+
break;
|
|
37
|
+
case ".scss":
|
|
38
|
+
fileName = fileName.replace(".scss", ".[contenthash].css");
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
entryPoints[entryName] = {
|
|
42
|
+
import: resolve(path, "../", value.slice(5)),
|
|
43
|
+
filename: fileName,
|
|
44
|
+
};
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
return { restOfPaths, entryPoints };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomicsmash/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"description": "A universal compiler for all Atomic Smash projects.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cli",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"lint:types": "tsc"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@atomicsmash/date-php": "^2.2.0
|
|
50
|
-
"@atomicsmash/smash-config": "^1.0.2
|
|
49
|
+
"@atomicsmash/date-php": "^2.2.0",
|
|
50
|
+
"@atomicsmash/smash-config": "^1.0.2",
|
|
51
51
|
"@wordpress/dependency-extraction-webpack-plugin": "^6.41.0",
|
|
52
52
|
"browserslist-to-esbuild": "^2.1.1",
|
|
53
53
|
"copy-webpack-plugin": "^14.0.0",
|