@atomicsmash/compiler 4.0.0-beta.4 → 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
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.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,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,M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;;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.");
|
|
@@ -121,8 +121,9 @@ export async function config(options) {
|
|
|
121
121
|
`${srcFolder}/styles/**/[^_]*.s[ac]ss`,
|
|
122
122
|
], {
|
|
123
123
|
ignore: [
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- Support for a few more versions to allow migration
|
|
124
125
|
...argv.excludeBlocks.map((blockName) => `${srcFolder}/blocks/**/${blockName}/block.json.ts`),
|
|
125
|
-
|
|
126
|
+
"!**/_*/**", // Exclude any folder that starts with an underscore for all files
|
|
126
127
|
],
|
|
127
128
|
}).then(async (paths) => {
|
|
128
129
|
const { restOfPaths, entryPoints } = await getBlocksAssetsEntryPoints(paths, {}, srcFolder);
|
|
@@ -325,7 +326,8 @@ export async function config(options) {
|
|
|
325
326
|
entry.key = "icons/sprite.svg";
|
|
326
327
|
return entry;
|
|
327
328
|
}
|
|
328
|
-
if (entry.key.startsWith("icons/sprite") &&
|
|
329
|
+
if (entry.key.startsWith("icons/sprite") &&
|
|
330
|
+
entry.key.endsWith(".svg")) {
|
|
329
331
|
entry.key = "icons/sprite.svg";
|
|
330
332
|
return entry;
|
|
331
333
|
}
|
|
@@ -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",
|