@crxjs/vite-plugin 1.0.4 → 1.0.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @crxjs/vite-plugin
2
2
 
3
+ ## 1.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 86adbec: Sometimes during development, an extension page may open before the
8
+ service worker has a chance to control fetch. The HTML file will load from the
9
+ file system, but the script tag might load from the dev server. This PR adds a
10
+ precontroller loader plugin to the dev server so that the extension page will
11
+ reload and the fetch handler will get the real HTML file from the server.
12
+
3
13
  ## 1.0.4
4
14
 
5
15
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -2094,27 +2094,40 @@ const pluginFileWriterEvents = () => {
2094
2094
  };
2095
2095
  };
2096
2096
 
2097
- var preControllerScript = "const id = setInterval(() => location.reload(), 100);\nsetTimeout(() => clearInterval(id), 5e3);\n";
2097
+ var precontrollerScript = "const id = setInterval(() => location.reload(), 100);\nsetTimeout(() => clearInterval(id), 5e3);\n";
2098
2098
 
2099
- var preControllerHtml = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <title>Waiting for the extension service worker...</title>\n <script src=\"%PATH%\"></script>\n </head>\n <body>\n <h1>Waiting for service worker</h1>\n\n <p>\n If you see this message, it means the service worker has not loaded fully.\n </p>\n\n <p>\n During development, the service worker reroutes HTML requests to the dev\n server, so this file isn't used unless the extension service worker opens\n a page immediately after a full extension reload, and before the service\n worker takes control of fetch (e.g., in the onInstalled event). In that\n case, this page will continuously reload until the service worker is\n ready, always less than 100 ms.\n </p>\n\n <p>This page is never added in production.</p>\n </body>\n</html>\n";
2099
+ var precontrollerHtml = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <title>Waiting for the extension service worker...</title>\n <script src=\"%PATH%\"></script>\n </head>\n <body>\n <h1>Waiting for service worker</h1>\n\n <p>\n If you see this message, it means the service worker has not loaded fully.\n </p>\n\n <p>This page is never added in production.</p>\n </body>\n</html>\n";
2100
2100
 
2101
2101
  const pluginFileWriterHtml = () => {
2102
+ let precontrollerName;
2102
2103
  return {
2103
2104
  name: "crx:file-writer-html",
2104
2105
  apply: "build",
2106
+ fileWriterStart(server) {
2107
+ const plugins = server.config.plugins;
2108
+ const i = plugins.findIndex(({ name }) => name === "alias");
2109
+ plugins.splice(i, 0, {
2110
+ name: "crx:load-precontroller",
2111
+ apply: "serve",
2112
+ load(id) {
2113
+ if (id === `/${precontrollerName}`)
2114
+ return "location.reload();";
2115
+ }
2116
+ });
2117
+ },
2105
2118
  renderCrxManifest(manifest) {
2106
2119
  if (this.meta.watchMode) {
2107
2120
  const refId = this.emitFile({
2108
2121
  type: "asset",
2109
2122
  name: "precontroller.js",
2110
- source: preControllerScript
2123
+ source: precontrollerScript
2111
2124
  });
2112
- const name = this.getFileName(refId);
2125
+ precontrollerName = this.getFileName(refId);
2113
2126
  for (const fileName of htmlFiles(manifest)) {
2114
2127
  this.emitFile({
2115
2128
  type: "asset",
2116
2129
  fileName,
2117
- source: preControllerHtml.replace("%PATH%", `/${name}`)
2130
+ source: precontrollerHtml.replace("%PATH%", `/${precontrollerName}`)
2118
2131
  });
2119
2132
  }
2120
2133
  }
package/dist/index.mjs CHANGED
@@ -2061,27 +2061,40 @@ const pluginFileWriterEvents = () => {
2061
2061
  };
2062
2062
  };
2063
2063
 
2064
- var preControllerScript = "const id = setInterval(() => location.reload(), 100);\nsetTimeout(() => clearInterval(id), 5e3);\n";
2064
+ var precontrollerScript = "const id = setInterval(() => location.reload(), 100);\nsetTimeout(() => clearInterval(id), 5e3);\n";
2065
2065
 
2066
- var preControllerHtml = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <title>Waiting for the extension service worker...</title>\n <script src=\"%PATH%\"></script>\n </head>\n <body>\n <h1>Waiting for service worker</h1>\n\n <p>\n If you see this message, it means the service worker has not loaded fully.\n </p>\n\n <p>\n During development, the service worker reroutes HTML requests to the dev\n server, so this file isn't used unless the extension service worker opens\n a page immediately after a full extension reload, and before the service\n worker takes control of fetch (e.g., in the onInstalled event). In that\n case, this page will continuously reload until the service worker is\n ready, always less than 100 ms.\n </p>\n\n <p>This page is never added in production.</p>\n </body>\n</html>\n";
2066
+ var precontrollerHtml = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <title>Waiting for the extension service worker...</title>\n <script src=\"%PATH%\"></script>\n </head>\n <body>\n <h1>Waiting for service worker</h1>\n\n <p>\n If you see this message, it means the service worker has not loaded fully.\n </p>\n\n <p>This page is never added in production.</p>\n </body>\n</html>\n";
2067
2067
 
2068
2068
  const pluginFileWriterHtml = () => {
2069
+ let precontrollerName;
2069
2070
  return {
2070
2071
  name: "crx:file-writer-html",
2071
2072
  apply: "build",
2073
+ fileWriterStart(server) {
2074
+ const plugins = server.config.plugins;
2075
+ const i = plugins.findIndex(({ name }) => name === "alias");
2076
+ plugins.splice(i, 0, {
2077
+ name: "crx:load-precontroller",
2078
+ apply: "serve",
2079
+ load(id) {
2080
+ if (id === `/${precontrollerName}`)
2081
+ return "location.reload();";
2082
+ }
2083
+ });
2084
+ },
2072
2085
  renderCrxManifest(manifest) {
2073
2086
  if (this.meta.watchMode) {
2074
2087
  const refId = this.emitFile({
2075
2088
  type: "asset",
2076
2089
  name: "precontroller.js",
2077
- source: preControllerScript
2090
+ source: precontrollerScript
2078
2091
  });
2079
- const name = this.getFileName(refId);
2092
+ precontrollerName = this.getFileName(refId);
2080
2093
  for (const fileName of htmlFiles(manifest)) {
2081
2094
  this.emitFile({
2082
2095
  type: "asset",
2083
2096
  fileName,
2084
- source: preControllerHtml.replace("%PATH%", `/${name}`)
2097
+ source: precontrollerHtml.replace("%PATH%", `/${precontrollerName}`)
2085
2098
  });
2086
2099
  }
2087
2100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crxjs/vite-plugin",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Build Chrome Extensions with this Vite plugin.",
5
5
  "keywords": [
6
6
  "rollup-plugin",
@@ -82,10 +82,10 @@
82
82
  "@rollup/plugin-commonjs": "21.1.0",
83
83
  "@rollup/plugin-node-resolve": "13.2.0",
84
84
  "@types/acorn": "4.0.6",
85
- "@types/chrome": "0.0.183",
85
+ "@types/chrome": "0.0.184",
86
86
  "@types/debug": "4.1.7",
87
87
  "@types/fs-extra": "9.0.13",
88
- "@types/jest": "27.4.1",
88
+ "@types/jest": "27.5.0",
89
89
  "@types/jest-image-snapshot": "4.3.1",
90
90
  "@types/jsesc": "3.0.1",
91
91
  "@types/node": "17.0.18",
@@ -94,7 +94,7 @@
94
94
  "@typescript-eslint/eslint-plugin": "5.21.0",
95
95
  "@typescript-eslint/parser": "5.21.0",
96
96
  "@vitejs/plugin-react": "1.3.1",
97
- "@vitejs/plugin-vue": "2.3.1",
97
+ "@vitejs/plugin-vue": "2.3.2",
98
98
  "esbuild": "0.14.38",
99
99
  "esbuild-runner": "2.2.1",
100
100
  "eslint": "^8.14.0",