@atomicsmash/compiler 2.0.0-beta.7 → 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.
@@ -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;AAS/D,qBAAa,YAAa,YAAW,qBAAqB;IACzD,UAAU,SAAkB;IAC5B,SAAS,EAAE,MAAM,CAAC;gBAEN,SAAS,EAAE,MAAM;IAI7B,KAAK,CAAC,QAAQ,EAAE,QAAQ;CA8JxB"}
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"}
@@ -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: "CustomBlocksCSSHandler",
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":";AAQA,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"}
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
- // import type { Configuration } from "webpack";
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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atomicsmash/compiler",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.7",
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",