@atomicsmash/compiler 4.0.0-beta.4 → 5.0.0-beta.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 -8
- package/dist/config.d.ts +3 -10
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -40
- package/dist/getBlocksAssetsEntryPoints.d.ts.map +1 -1
- package/dist/getBlocksAssetsEntryPoints.js +28 -30
- package/package.json +14 -14
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,7 +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
|
+
deprecate: "Use folders which start with an underscore instead.",
|
|
39
39
|
},
|
|
40
40
|
})
|
|
41
41
|
.showHelpOnFail(false, "Specify --help for available options")
|
|
@@ -43,9 +43,6 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
43
43
|
// eslint-disable-next-line @typescript-eslint/naming-convention -- Experimental option.
|
|
44
44
|
const { experimentalBlocksSupport, ...compilerOptions } = argv;
|
|
45
45
|
const compiler = webpack(await defaultConfig({ ...compilerOptions }));
|
|
46
|
-
if (!compiler) {
|
|
47
|
-
throw new Error("Failed to initialise compiler.");
|
|
48
|
-
}
|
|
49
46
|
if (argv.watch) {
|
|
50
47
|
let i = 0;
|
|
51
48
|
console.log("Starting dev compiler.");
|
|
@@ -64,14 +61,14 @@ if (argv.watch) {
|
|
|
64
61
|
else if (stats && i > 0) {
|
|
65
62
|
const info = stats.toJson();
|
|
66
63
|
if (stats.hasErrors()) {
|
|
67
|
-
const errors = info.errors;
|
|
64
|
+
const errors = info.errors ?? [];
|
|
68
65
|
console.warn("The compiler produced the following errors: \n");
|
|
69
66
|
for (const error of errors) {
|
|
70
67
|
console.warn(error.message);
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
if (stats.hasWarnings()) {
|
|
74
|
-
const warnings = info.warnings;
|
|
71
|
+
const warnings = info.warnings ?? [];
|
|
75
72
|
console.warn("The compiler produced the following warnings: \n");
|
|
76
73
|
for (const warning of warnings) {
|
|
77
74
|
console.warn(warning.message);
|
|
@@ -104,7 +101,7 @@ else {
|
|
|
104
101
|
else if (stats) {
|
|
105
102
|
const info = stats.toJson();
|
|
106
103
|
if (stats.hasErrors()) {
|
|
107
|
-
const errors = info.errors;
|
|
104
|
+
const errors = info.errors ?? [];
|
|
108
105
|
console.warn("The compiler produced the following errors: \n");
|
|
109
106
|
for (const error of errors) {
|
|
110
107
|
console.warn(error.message);
|
|
@@ -112,7 +109,7 @@ else {
|
|
|
112
109
|
process.exitCode = 1;
|
|
113
110
|
}
|
|
114
111
|
if (stats.hasWarnings()) {
|
|
115
|
-
const warnings = info.warnings;
|
|
112
|
+
const warnings = info.warnings ?? [];
|
|
116
113
|
console.warn("The compiler produced the following warnings: \n");
|
|
117
114
|
for (const warning of warnings) {
|
|
118
115
|
console.warn(warning.message);
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { SCSSAliases } from "@atomicsmash/smash-config";
|
|
2
1
|
import type { PathData } from "webpack";
|
|
3
2
|
import DependencyExtractionWebpackPlugin from "@wordpress/dependency-extraction-webpack-plugin";
|
|
4
3
|
import CopyPlugin from "copy-webpack-plugin";
|
|
@@ -63,7 +62,7 @@ export declare function config(options: {
|
|
|
63
62
|
use: {
|
|
64
63
|
loader: string;
|
|
65
64
|
options: {
|
|
66
|
-
loader: "
|
|
65
|
+
loader: "ts" | "default";
|
|
67
66
|
target: string[];
|
|
68
67
|
tsconfig: string;
|
|
69
68
|
};
|
|
@@ -108,13 +107,7 @@ export declare function config(options: {
|
|
|
108
107
|
options: {
|
|
109
108
|
postcssOptions: {
|
|
110
109
|
sourceMap: boolean;
|
|
111
|
-
plugins: (typeof cssNano | (import("postcss").Processor | import("postcss").PluginCreator<
|
|
112
|
-
base?: string;
|
|
113
|
-
optimize?: boolean | {
|
|
114
|
-
minify?: boolean;
|
|
115
|
-
};
|
|
116
|
-
transformAssetUrls?: boolean;
|
|
117
|
-
}> | typeof import("tailwindcss").default | import("postcss").Plugin)[])[];
|
|
110
|
+
plugins: (typeof cssNano | (import("postcss").Processor | import("postcss").PluginCreator<import("@tailwindcss/postcss").PluginOptions> | typeof import("tailwindcss").default | import("postcss").Plugin)[])[];
|
|
118
111
|
};
|
|
119
112
|
sourceMap?: undefined;
|
|
120
113
|
sassOptions?: undefined;
|
|
@@ -123,7 +116,7 @@ export declare function config(options: {
|
|
|
123
116
|
loader: string;
|
|
124
117
|
options: {
|
|
125
118
|
sourceMap: boolean;
|
|
126
|
-
sassOptions: SCSSAliases;
|
|
119
|
+
sassOptions: import("@atomicsmash/smash-config").SCSSAliases;
|
|
127
120
|
postcssOptions?: undefined;
|
|
128
121
|
};
|
|
129
122
|
})[];
|
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,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,QAAQ,EAAe,MAAM,SAAS,CAAC;AASpE,OAAO,iCAAiC,MAAM,iDAAiD,CAAC;AAEhG,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG/C,OAAO,kBAAkB,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yCAkM4B,QAAQ;;;;;;;;;;;;;;;qCAeV,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwMlC"}
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { sep as pathSeparator, extname, resolve as resolvePath, relative, join, } from "node:path";
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
3
2
|
import { getSmashConfig } from "@atomicsmash/smash-config";
|
|
4
3
|
import DependencyExtractionWebpackPlugin from "@wordpress/dependency-extraction-webpack-plugin";
|
|
5
4
|
import browserslistToEsbuild from "browserslist-to-esbuild";
|
|
@@ -28,17 +27,10 @@ export async function config(options) {
|
|
|
28
27
|
: "production";
|
|
29
28
|
const srcFolder = argv.in
|
|
30
29
|
? resolvePath(argv.in)
|
|
31
|
-
: smashConfig
|
|
32
|
-
? resolvePath(join(smashConfig?.themePath, "src"))
|
|
33
|
-
: null;
|
|
30
|
+
: resolvePath(join(smashConfig.themePath, "src"));
|
|
34
31
|
const distFolder = argv.out
|
|
35
32
|
? resolvePath(argv.out)
|
|
36
|
-
: smashConfig
|
|
37
|
-
? resolvePath(join(smashConfig?.themePath, smashConfig.assetsOutputFolder))
|
|
38
|
-
: null;
|
|
39
|
-
if (!srcFolder || !distFolder) {
|
|
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.");
|
|
41
|
-
}
|
|
33
|
+
: resolvePath(join(smashConfig.themePath, smashConfig.assetsOutputFolder));
|
|
42
34
|
// Add optional support for Tailwind if tailwind postcss plugin is installed
|
|
43
35
|
const tailwindPostCSSPlugin = await import("@tailwindcss/postcss")
|
|
44
36
|
.then((tailwindPostCSS) => [tailwindPostCSS.default])
|
|
@@ -121,8 +113,9 @@ export async function config(options) {
|
|
|
121
113
|
`${srcFolder}/styles/**/[^_]*.s[ac]ss`,
|
|
122
114
|
], {
|
|
123
115
|
ignore: [
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- Support for a few more versions to allow migration
|
|
124
117
|
...argv.excludeBlocks.map((blockName) => `${srcFolder}/blocks/**/${blockName}/block.json.ts`),
|
|
125
|
-
|
|
118
|
+
"!**/_*/**", // Exclude any folder that starts with an underscore for all files
|
|
126
119
|
],
|
|
127
120
|
}).then(async (paths) => {
|
|
128
121
|
const { restOfPaths, entryPoints } = await getBlocksAssetsEntryPoints(paths, {}, srcFolder);
|
|
@@ -249,7 +242,7 @@ export async function config(options) {
|
|
|
249
242
|
loader: "sass-loader",
|
|
250
243
|
options: {
|
|
251
244
|
sourceMap: MODE === "development",
|
|
252
|
-
sassOptions:
|
|
245
|
+
sassOptions: smashConfig.scssAliases,
|
|
253
246
|
},
|
|
254
247
|
},
|
|
255
248
|
],
|
|
@@ -325,7 +318,8 @@ export async function config(options) {
|
|
|
325
318
|
entry.key = "icons/sprite.svg";
|
|
326
319
|
return entry;
|
|
327
320
|
}
|
|
328
|
-
if (entry.key.startsWith("icons/sprite") &&
|
|
321
|
+
if (entry.key.startsWith("icons/sprite") &&
|
|
322
|
+
entry.key.endsWith(".svg")) {
|
|
329
323
|
entry.key = "icons/sprite.svg";
|
|
330
324
|
return entry;
|
|
331
325
|
}
|
|
@@ -396,30 +390,3 @@ export async function config(options) {
|
|
|
396
390
|
},
|
|
397
391
|
};
|
|
398
392
|
}
|
|
399
|
-
async function getSassOptions(srcFolder) {
|
|
400
|
-
const smashConfig = await getSmashConfig();
|
|
401
|
-
if (smashConfig) {
|
|
402
|
-
return smashConfig.scssAliases;
|
|
403
|
-
}
|
|
404
|
-
const defaultConfig = {
|
|
405
|
-
importers: [
|
|
406
|
-
{
|
|
407
|
-
findFileUrl(url) {
|
|
408
|
-
if (!url.startsWith("sitecss:"))
|
|
409
|
-
return null;
|
|
410
|
-
const pathname = url.substring(8);
|
|
411
|
-
return pathToFileURL(`${resolvePath(srcFolder, "../css")}${pathname.startsWith("/") ? pathname : `/${pathname}`}`);
|
|
412
|
-
},
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
findFileUrl(url) {
|
|
416
|
-
if (!url.startsWith("launchpad:"))
|
|
417
|
-
return null;
|
|
418
|
-
const pathname = url.substring(10);
|
|
419
|
-
return pathToFileURL(`${resolvePath(process.cwd(), "public/wp-content/themes/launchpad/src/styles")}${pathname.startsWith("/") ? pathname : `/${pathname}`}`);
|
|
420
|
-
},
|
|
421
|
-
},
|
|
422
|
-
],
|
|
423
|
-
};
|
|
424
|
-
return defaultConfig;
|
|
425
|
-
}
|
|
@@ -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
|
+
"version": "5.0.0-beta.0",
|
|
5
5
|
"description": "A universal compiler for all Atomic Smash projects.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cli",
|
|
@@ -46,35 +46,35 @@
|
|
|
46
46
|
"lint:types": "tsc"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@atomicsmash/date-php": "^2.2.0
|
|
50
|
-
"@atomicsmash/smash-config": "^
|
|
51
|
-
"@wordpress/dependency-extraction-webpack-plugin": "^6.
|
|
49
|
+
"@atomicsmash/date-php": "^2.2.0",
|
|
50
|
+
"@atomicsmash/smash-config": "^2.0.0-beta.0",
|
|
51
|
+
"@wordpress/dependency-extraction-webpack-plugin": "^6.48.1",
|
|
52
52
|
"browserslist-to-esbuild": "^2.1.1",
|
|
53
53
|
"copy-webpack-plugin": "^14.0.0",
|
|
54
|
-
"
|
|
55
|
-
"esbuild-loader": "^4.4.2",
|
|
54
|
+
"esbuild-loader": "^4.5.0",
|
|
56
55
|
"fast-glob": "^3.3.3",
|
|
57
56
|
"json-loader": "^0.5.7",
|
|
58
57
|
"json2php": "^0.0.12",
|
|
59
58
|
"postcss": "^8.5.8",
|
|
60
59
|
"postcss-loader": "^8.2.1",
|
|
61
|
-
"postcss-preset-env": "^11.
|
|
62
|
-
"sass": "^1.
|
|
63
|
-
"sass-loader": "^16.0.7",
|
|
60
|
+
"postcss-preset-env": "^11.3.1",
|
|
61
|
+
"sass": "^1.101.0",
|
|
64
62
|
"svg-spritemap-webpack-plugin": "^5.1.0",
|
|
65
63
|
"tsconfig-paths-webpack-plugin": "^4.2.0",
|
|
66
|
-
"tsx": "^4.
|
|
67
|
-
"webpack": "^5.
|
|
68
|
-
"webpack-assets-manifest": "^6.5.
|
|
69
|
-
"webpack-bundle-analyzer": "^5.
|
|
64
|
+
"tsx": "^4.22.4",
|
|
65
|
+
"webpack": "^5.107.2",
|
|
66
|
+
"webpack-assets-manifest": "^6.5.2",
|
|
67
|
+
"webpack-bundle-analyzer": "^5.3.0",
|
|
70
68
|
"yargs": "^18.0.0"
|
|
71
69
|
},
|
|
72
70
|
"devDependencies": {
|
|
73
|
-
"@tailwindcss/postcss": "^4.
|
|
71
|
+
"@tailwindcss/postcss": "^4.3.1",
|
|
74
72
|
"@types/webpack": "^5.28.5",
|
|
75
73
|
"@types/webpack-assets-manifest": "^5.1.4",
|
|
76
74
|
"@types/webpack-bundle-analyzer": "^4.7.0",
|
|
77
75
|
"@types/yargs": "^17.0.35",
|
|
76
|
+
"cssnano": "^8.0.2",
|
|
77
|
+
"sass-loader": "^17.0.0",
|
|
78
78
|
"tailwindcss": "^4.0.9",
|
|
79
79
|
"vue-loader": "^17.4.2"
|
|
80
80
|
},
|