@crxjs/vite-plugin 2.0.0-beta.10 → 2.0.0-beta.11

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.
Files changed (2) hide show
  1. package/dist/index.mjs +30 -2
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -455,7 +455,8 @@ function prepScript(fileName, script) {
455
455
  if (i.n) {
456
456
  depSet.add(i.n);
457
457
  const fileName2 = getFileName({ type: "module", id: i.n });
458
- magic.overwrite(i.s, i.e, `/${fileName2}`);
458
+ const fullImport = code.substring(i.s, i.e);
459
+ magic.overwrite(i.s, i.e, fullImport.replace(i.n, `/${fileName2}`));
459
460
  }
460
461
  return { target, source: magic.toString(), deps: [...depSet] };
461
462
  })
@@ -707,6 +708,34 @@ const pluginDynamicContentScripts = () => {
707
708
  configResolved(_config) {
708
709
  config = _config;
709
710
  },
711
+ configureServer(server) {
712
+ return () => {
713
+ server.middlewares.use(async (req, res, next) => {
714
+ try {
715
+ await allFilesReady();
716
+ next();
717
+ } catch (error) {
718
+ let err;
719
+ if (error instanceof Error) {
720
+ err = error;
721
+ } else if (typeof error === "string") {
722
+ err = new Error(error);
723
+ } else {
724
+ err = new Error(
725
+ `Unexpected error "${error}" in middleware for "${req.url}"`
726
+ );
727
+ }
728
+ server.ws.send({
729
+ type: "error",
730
+ err: {
731
+ message: err.message,
732
+ stack: err.stack ?? "no stack available"
733
+ }
734
+ });
735
+ }
736
+ });
737
+ };
738
+ },
710
739
  async resolveId(_source, importer) {
711
740
  if (importer && _source.includes("?script")) {
712
741
  const url = new URL(_source, "stub://stub");
@@ -775,7 +804,6 @@ const pluginDynamicContentScripts = () => {
775
804
  if (config.command === "build") {
776
805
  return `export default import.meta.CRX_DYNAMIC_SCRIPT_${script.refId};`;
777
806
  } else if (typeof script.fileName === "string") {
778
- await fileReady(script);
779
807
  return `export default ${JSON.stringify(script.fileName)};`;
780
808
  } else {
781
809
  throw new Error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crxjs/vite-plugin",
3
- "version": "2.0.0-beta.10",
3
+ "version": "2.0.0-beta.11",
4
4
  "description": "Build Chrome Extensions with this Vite plugin.",
5
5
  "keywords": [
6
6
  "rollup-plugin",
@@ -88,7 +88,7 @@
88
88
  "@rollup/plugin-node-resolve": "13.2.0",
89
89
  "@sveltejs/vite-plugin-svelte": "1.1.0",
90
90
  "@types/acorn": "4.0.6",
91
- "@types/chrome": "0.0.198",
91
+ "@types/chrome": "0.0.209",
92
92
  "@types/debug": "4.1.7",
93
93
  "@types/fs-extra": "9.0.13",
94
94
  "@types/jest-image-snapshot": "^5.1.0",