@atomicsmash/compiler 2.0.0-beta.6 → 2.0.0-beta.8
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.d.ts.map +1 -1
- package/dist/BlocksPlugin.js +11 -4
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +14 -3
- package/dist/config.d.ts +0 -11
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -10
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlocksPlugin.d.ts","sourceRoot":"","sources":["../src/BlocksPlugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"BlocksPlugin.d.ts","sourceRoot":"","sources":["../src/BlocksPlugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAU/D,qBAAa,YAAa,YAAW,qBAAqB;IACzD,UAAU,SAAkB;IAC5B,SAAS,EAAE,MAAM,CAAC;gBAEN,SAAS,EAAE,MAAM;IAI7B,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAuKxB"}
|
package/dist/BlocksPlugin.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { readFile, writeFile, unlink as deleteFile } from "node:fs/promises";
|
|
2
3
|
import { extname, resolve, relative, sep as pathSeparator } from "node:path";
|
|
3
4
|
import glob from "fast-glob";
|
|
@@ -14,7 +15,7 @@ export class BlocksPlugin {
|
|
|
14
15
|
const { webpack: { Compilation, sources }, } = compiler;
|
|
15
16
|
compiler.hooks.thisCompilation.tap(this.pluginName, (compilation) => {
|
|
16
17
|
compilation.hooks.processAssets.tapPromise({
|
|
17
|
-
name: "
|
|
18
|
+
name: "CopyPHPFiles",
|
|
18
19
|
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
|
|
19
20
|
}, async (assets) => {
|
|
20
21
|
const blockJsonFiles = Object.keys(assets).filter((asset) => asset.endsWith("block.json"));
|
|
@@ -61,16 +62,22 @@ export class BlocksPlugin {
|
|
|
61
62
|
newValues.push(srcFilePath);
|
|
62
63
|
continue;
|
|
63
64
|
}
|
|
64
|
-
const fileName = srcFilePath
|
|
65
|
+
const [fileName, contentHash] = srcFilePath
|
|
65
66
|
.replace("file:./", "")
|
|
66
|
-
.replace(extname(srcFilePath), "")
|
|
67
|
+
.replace(extname(srcFilePath), "")
|
|
68
|
+
.split(".");
|
|
67
69
|
const hashedAsset = Object.keys(compilation.assets).find((asset) => {
|
|
68
70
|
return (asset.startsWith(`${blockName}${pathSeparator}${fileName}`) && !asset.endsWith(".php"));
|
|
69
71
|
});
|
|
70
|
-
if (hashedAsset
|
|
72
|
+
if (hashedAsset &&
|
|
73
|
+
(!contentHash || !hashedAsset.includes(contentHash))) {
|
|
71
74
|
if (hashedAsset in wordpressAssets) {
|
|
72
75
|
await writeFile(`${compilation.outputOptions.path}${pathSeparator}${hashedAsset.replace(extname(hashedAsset), ".asset.php")}`, `<?php return ${printer(wordpressAssets[hashedAsset])};\n`, "utf-8");
|
|
73
76
|
}
|
|
77
|
+
const oldAssetFileLocation = `${compilation.outputOptions.path}${pathSeparator}${blockName}${pathSeparator}${fileName}.${contentHash}.asset.php`;
|
|
78
|
+
if (contentHash && existsSync(oldAssetFileLocation)) {
|
|
79
|
+
await deleteFile(oldAssetFileLocation);
|
|
80
|
+
}
|
|
74
81
|
newValues.push(`file:./${hashedAsset.replace(`${blockName}${pathSeparator}`, "")}`);
|
|
75
82
|
}
|
|
76
83
|
else {
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAOA,OAAO,CAAC,MAAM,CAAC;IAEd,UAAU,MAAM,CAAC;QAEhB,UAAU,UAAU;YACnB,QAAQ,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,CAAC;SAC5D;KACD;CACD"}
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// import { cosmiconfig } from "cosmiconfig";
|
|
2
|
+
import { DatePHP } from "@atomicsmash/date-php";
|
|
4
3
|
import webpack from "webpack";
|
|
5
4
|
import yargs from "yargs";
|
|
6
5
|
import { hideBin } from "yargs/helpers";
|
|
@@ -44,6 +43,8 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
44
43
|
const { experimentalBlocksSupport, ...compilerOptions } = argv;
|
|
45
44
|
const compiler = webpack(await defaultConfig({ ...compilerOptions }));
|
|
46
45
|
if (argv.watch) {
|
|
46
|
+
let i = 0;
|
|
47
|
+
console.log("Starting dev compiler.");
|
|
47
48
|
const watching = compiler.watch({
|
|
48
49
|
// Example
|
|
49
50
|
aggregateTimeout: 300,
|
|
@@ -56,7 +57,7 @@ if (argv.watch) {
|
|
|
56
57
|
console.error(closeError);
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
|
-
else if (stats) {
|
|
60
|
+
else if (stats && i > 0) {
|
|
60
61
|
const info = stats.toJson();
|
|
61
62
|
if (stats.hasErrors()) {
|
|
62
63
|
const errors = info.errors;
|
|
@@ -72,7 +73,17 @@ if (argv.watch) {
|
|
|
72
73
|
console.warn(warning.message);
|
|
73
74
|
}
|
|
74
75
|
}
|
|
76
|
+
if (i === 1) {
|
|
77
|
+
console.log("Started watching files.");
|
|
78
|
+
}
|
|
79
|
+
else if (!stats.hasErrors() && !stats.hasWarnings()) {
|
|
80
|
+
console.log(`Recompiled successfully at ${new DatePHP().format("jS F Y \\a\\t H:i:s")}`);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
console.log(`Recompiled with errors at ${new DatePHP().format("jS F Y \\a\\t H:i:s")}`);
|
|
84
|
+
}
|
|
75
85
|
}
|
|
86
|
+
i++;
|
|
76
87
|
});
|
|
77
88
|
process.on("SIGINT", function () {
|
|
78
89
|
watching.close((closeError) => {
|
package/dist/config.d.ts
CHANGED
|
@@ -94,17 +94,6 @@ export declare function config(options: {
|
|
|
94
94
|
type?: undefined;
|
|
95
95
|
generator?: undefined;
|
|
96
96
|
use?: undefined;
|
|
97
|
-
} | {
|
|
98
|
-
test: RegExp;
|
|
99
|
-
type: string;
|
|
100
|
-
generator: {
|
|
101
|
-
filename: (pathData: PathData) => string;
|
|
102
|
-
binary?: undefined;
|
|
103
|
-
};
|
|
104
|
-
use: {
|
|
105
|
-
loader: string;
|
|
106
|
-
};
|
|
107
|
-
oneOf?: undefined;
|
|
108
97
|
} | {
|
|
109
98
|
test: RegExp;
|
|
110
99
|
type: string;
|
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,EAAiB,QAAQ,EAAe,MAAM,SAAS,CAAC;AAUpE,OAAO,iCAAiC,MAAM,iDAAiD,CAAC;AAEhG,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAE7C,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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EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yCAyM4B,QAAQ;;;;;;;;;;;;;;;qCAeV,QAAQ;;;;;;;;;;sCApQrB,CAAC;;;;;;;;;;;;;;;;;;;;;;GA+bd"}
|
package/dist/config.js
CHANGED
|
@@ -201,16 +201,6 @@ export async function config(options) {
|
|
|
201
201
|
},
|
|
202
202
|
],
|
|
203
203
|
},
|
|
204
|
-
{
|
|
205
|
-
test: /block\.json\.ts$/,
|
|
206
|
-
type: "asset/resource",
|
|
207
|
-
generator: {
|
|
208
|
-
filename: (pathData) => relative(srcFolder, pathData.filename ?? "").slice(0, -3),
|
|
209
|
-
},
|
|
210
|
-
use: {
|
|
211
|
-
loader: resolvePath(import.meta.dirname, "./BlocksLoader.js"),
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
204
|
// Transpile SCSS files and run the result through postcss
|
|
215
205
|
{
|
|
216
206
|
test: /\.s[ac]ss$/i,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomicsmash/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.8",
|
|
5
5
|
"description": "A universal compiler for all Atomic Smash projects.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cli",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"lint:types": "tsc"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
+
"@atomicsmash/date-php": "^2.1.0",
|
|
49
50
|
"@wordpress/dependency-extraction-webpack-plugin": "^6.27.0",
|
|
50
51
|
"browserslist-to-esbuild": "^2.1.1",
|
|
51
52
|
"copy-webpack-plugin": "^12.0.2",
|