@atomicsmash/compiler 2.0.0-beta.7 → 2.0.0-beta.9

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";
@@ -43,7 +42,12 @@ const argv = await yargs(hideBin(process.argv))
43
42
  // eslint-disable-next-line @typescript-eslint/naming-convention -- Experimental option.
44
43
  const { experimentalBlocksSupport, ...compilerOptions } = argv;
45
44
  const compiler = webpack(await defaultConfig({ ...compilerOptions }));
45
+ if (!compiler) {
46
+ throw new Error("Failed to initialise compiler.");
47
+ }
46
48
  if (argv.watch) {
49
+ let i = 0;
50
+ console.log("Starting dev compiler.");
47
51
  const watching = compiler.watch({
48
52
  // Example
49
53
  aggregateTimeout: 300,
@@ -52,11 +56,11 @@ if (argv.watch) {
52
56
  if (error) {
53
57
  console.error(error.stack ?? error);
54
58
  process.exitCode = 1;
55
- watching.close((closeError) => {
59
+ watching?.close((closeError) => {
56
60
  console.error(closeError);
57
61
  });
58
62
  }
59
- else if (stats) {
63
+ else if (stats && i > 0) {
60
64
  const info = stats.toJson();
61
65
  if (stats.hasErrors()) {
62
66
  const errors = info.errors;
@@ -72,10 +76,20 @@ if (argv.watch) {
72
76
  console.warn(warning.message);
73
77
  }
74
78
  }
79
+ if (i === 1) {
80
+ console.log("Started watching files.");
81
+ }
82
+ else if (!stats.hasErrors() && !stats.hasWarnings()) {
83
+ console.log(`Recompiled successfully at ${new DatePHP().format("jS F Y \\a\\t H:i:s")}`);
84
+ }
85
+ else {
86
+ console.log(`Recompiled with errors at ${new DatePHP().format("jS F Y \\a\\t H:i:s")}`);
87
+ }
75
88
  }
89
+ i++;
76
90
  });
77
91
  process.on("SIGINT", function () {
78
- watching.close((closeError) => {
92
+ watching?.close((closeError) => {
79
93
  console.error(closeError);
80
94
  });
81
95
  });
package/dist/config.d.ts CHANGED
@@ -111,6 +111,7 @@ export declare function config(options: {
111
111
  optimize?: boolean | {
112
112
  minify?: boolean;
113
113
  };
114
+ transformAssetUrls?: boolean;
114
115
  }> | typeof import("tailwindcss").default | import("postcss").Plugin)[])[];
115
116
  };
116
117
  sourceMap?: undefined;
@@ -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,mBAAmB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,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;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yCAy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b9C"}
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.9",
5
5
  "description": "A universal compiler for all Atomic Smash projects.",
6
6
  "keywords": [
7
7
  "cli",
@@ -46,30 +46,31 @@
46
46
  "lint:types": "tsc"
47
47
  },
48
48
  "dependencies": {
49
- "@wordpress/dependency-extraction-webpack-plugin": "^6.27.0",
49
+ "@atomicsmash/date-php": "^2.1.0",
50
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.32.0",
50
51
  "browserslist-to-esbuild": "^2.1.1",
51
52
  "copy-webpack-plugin": "^12.0.2",
52
53
  "cosmiconfig": "^9.0.0",
53
- "cssnano": "^7.1.0",
54
- "esbuild-loader": "^4.3.0",
54
+ "cssnano": "^7.1.1",
55
+ "esbuild-loader": "^4.4.0",
55
56
  "fast-glob": "^3.3.3",
56
57
  "json-loader": "^0.5.7",
57
58
  "json2php": "^0.0.12",
58
59
  "postcss": "^8.5.6",
59
- "postcss-loader": "^8.1.1",
60
- "postcss-preset-env": "^10.2.4",
61
- "sass": "^1.89.2",
62
- "sass-loader": "^16.0.4",
60
+ "postcss-loader": "^8.2.0",
61
+ "postcss-preset-env": "^10.4.0",
62
+ "sass": "^1.93.2",
63
+ "sass-loader": "^16.0.5",
63
64
  "svg-spritemap-webpack-plugin": "^4.7.0",
64
65
  "tsconfig-paths-webpack-plugin": "^4.2.0",
65
- "tsx": "^4.20.3",
66
- "webpack": "^5.100.2",
67
- "webpack-assets-manifest": "^6.2.1",
66
+ "tsx": "^4.20.6",
67
+ "webpack": "^5.102.1",
68
+ "webpack-assets-manifest": "^6.3.0",
68
69
  "webpack-bundle-analyzer": "^4.10.2",
69
70
  "yargs": "^17.7.2"
70
71
  },
71
72
  "devDependencies": {
72
- "@tailwindcss/postcss": "^4.1.11",
73
+ "@tailwindcss/postcss": "^4.1.14",
73
74
  "@types/svg-spritemap-webpack-plugin": "^4.4.4",
74
75
  "@types/webpack": "^5.28.5",
75
76
  "@types/webpack-assets-manifest": "^5.1.4",
@@ -82,6 +83,6 @@
82
83
  "node": "^20 || >=22"
83
84
  },
84
85
  "peerDependencies": {
85
- "@atomicsmash/cli": "^9.0.0-beta.6"
86
+ "@atomicsmash/cli": "^9.0.0-beta.13"
86
87
  }
87
88
  }