@crxjs/vite-plugin 1.0.2 → 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,29 @@
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
+
13
+ ## 1.0.4
14
+
15
+ ### Patch Changes
16
+
17
+ - b83a4bd: Check for manifest assets first in the project root, then check in
18
+ the public dir. Throw an informative error if the file does not exist in
19
+ either dir.
20
+
21
+ ## 1.0.3
22
+
23
+ ### Patch Changes
24
+
25
+ - 8b2e587: check service worker on interval from extension page
26
+
3
27
  ## 1.0.2
4
28
 
5
29
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -17,6 +17,7 @@ var vite = require('vite');
17
17
  var module$1 = require('module');
18
18
  var cheerio = require('cheerio');
19
19
  var jsesc = require('jsesc');
20
+ var fs = require('fs');
20
21
  var injector = require('connect-injector');
21
22
 
22
23
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -2093,27 +2094,40 @@ const pluginFileWriterEvents = () => {
2093
2094
  };
2094
2095
  };
2095
2096
 
2096
- var preControllerScript = "setTimeout(() => location.reload(), 100);\n";
2097
+ var precontrollerScript = "const id = setInterval(() => location.reload(), 100);\nsetTimeout(() => clearInterval(id), 5e3);\n";
2097
2098
 
2098
- 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";
2099
2100
 
2100
2101
  const pluginFileWriterHtml = () => {
2102
+ let precontrollerName;
2101
2103
  return {
2102
2104
  name: "crx:file-writer-html",
2103
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
+ },
2104
2118
  renderCrxManifest(manifest) {
2105
2119
  if (this.meta.watchMode) {
2106
2120
  const refId = this.emitFile({
2107
2121
  type: "asset",
2108
2122
  name: "precontroller.js",
2109
- source: preControllerScript
2123
+ source: precontrollerScript
2110
2124
  });
2111
- const name = this.getFileName(refId);
2125
+ precontrollerName = this.getFileName(refId);
2112
2126
  for (const fileName of htmlFiles(manifest)) {
2113
2127
  this.emitFile({
2114
2128
  type: "asset",
2115
2129
  fileName,
2116
- source: preControllerHtml.replace("%PATH%", `/${name}`)
2130
+ source: precontrollerHtml.replace("%PATH%", `/${precontrollerName}`)
2117
2131
  });
2118
2132
  }
2119
2133
  }
@@ -2731,7 +2745,14 @@ const pluginManifest = (_manifest) => () => {
2731
2745
  const files = await manifestFiles(manifest2);
2732
2746
  await Promise.all(assetTypes.map((k) => files[k]).flat().map(async (f) => {
2733
2747
  if (typeof bundle[f] === "undefined") {
2734
- const filename = join(config.root, f);
2748
+ let filename = join(config.root, f);
2749
+ if (!fs.existsSync(filename))
2750
+ filename = join(config.publicDir, f);
2751
+ if (!fs.existsSync(filename))
2752
+ throw new Error(`ENOENT: Could not load manifest asset "${f}".
2753
+ Manifest assets must exist in one of these directories:
2754
+ Project root: "${config.root}"
2755
+ Public dir: "${config.publicDir}"`);
2735
2756
  this.emitFile({
2736
2757
  type: "asset",
2737
2758
  fileName: f,
package/dist/index.mjs CHANGED
@@ -13,6 +13,7 @@ import { createLogger } from 'vite';
13
13
  import { createRequire } from 'module';
14
14
  import { load } from 'cheerio';
15
15
  import jsesc from 'jsesc';
16
+ import { existsSync } from 'fs';
16
17
  import injector from 'connect-injector';
17
18
 
18
19
  const _debug = (id) => debug$5("crx").extend(id);
@@ -2060,27 +2061,40 @@ const pluginFileWriterEvents = () => {
2060
2061
  };
2061
2062
  };
2062
2063
 
2063
- var preControllerScript = "setTimeout(() => location.reload(), 100);\n";
2064
+ var precontrollerScript = "const id = setInterval(() => location.reload(), 100);\nsetTimeout(() => clearInterval(id), 5e3);\n";
2064
2065
 
2065
- 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";
2066
2067
 
2067
2068
  const pluginFileWriterHtml = () => {
2069
+ let precontrollerName;
2068
2070
  return {
2069
2071
  name: "crx:file-writer-html",
2070
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
+ },
2071
2085
  renderCrxManifest(manifest) {
2072
2086
  if (this.meta.watchMode) {
2073
2087
  const refId = this.emitFile({
2074
2088
  type: "asset",
2075
2089
  name: "precontroller.js",
2076
- source: preControllerScript
2090
+ source: precontrollerScript
2077
2091
  });
2078
- const name = this.getFileName(refId);
2092
+ precontrollerName = this.getFileName(refId);
2079
2093
  for (const fileName of htmlFiles(manifest)) {
2080
2094
  this.emitFile({
2081
2095
  type: "asset",
2082
2096
  fileName,
2083
- source: preControllerHtml.replace("%PATH%", `/${name}`)
2097
+ source: precontrollerHtml.replace("%PATH%", `/${precontrollerName}`)
2084
2098
  });
2085
2099
  }
2086
2100
  }
@@ -2698,7 +2712,14 @@ const pluginManifest = (_manifest) => () => {
2698
2712
  const files = await manifestFiles(manifest2);
2699
2713
  await Promise.all(assetTypes.map((k) => files[k]).flat().map(async (f) => {
2700
2714
  if (typeof bundle[f] === "undefined") {
2701
- const filename = join(config.root, f);
2715
+ let filename = join(config.root, f);
2716
+ if (!existsSync(filename))
2717
+ filename = join(config.publicDir, f);
2718
+ if (!existsSync(filename))
2719
+ throw new Error(`ENOENT: Could not load manifest asset "${f}".
2720
+ Manifest assets must exist in one of these directories:
2721
+ Project root: "${config.root}"
2722
+ Public dir: "${config.publicDir}"`);
2702
2723
  this.emitFile({
2703
2724
  type: "asset",
2704
2725
  fileName: f,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crxjs/vite-plugin",
3
- "version": "1.0.2",
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",