@marko/vite 3.1.2 → 3.1.4

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/dist/index.js CHANGED
@@ -76,10 +76,8 @@ function markoPlugin(opts = {}) {
76
76
  let domConfig;
77
77
  let hydrateConfig;
78
78
  const resolveVirtualDependency = (from, dep) => {
79
- const query = `${virtualFileQuery}&id=${encodeURIComponent(
80
- normalizePath(dep.virtualPath)
81
- )}`;
82
79
  const normalizedFrom = normalizePath(from);
80
+ const query = `${virtualFileQuery}&id=${Buffer.from(dep.virtualPath).toString("base64url") + import_path.default.extname(dep.virtualPath)}`;
83
81
  const id = normalizePath(normalizedFrom) + query;
84
82
  if (devServer) {
85
83
  const prev = virtualFiles.get(id);
@@ -416,7 +414,7 @@ function markoPlugin(opts = {}) {
416
414
  cachedSources.set(id, source);
417
415
  }
418
416
  if (!query) {
419
- if (!isBuild && /[\\/]node_modules[\\/]/.test(id) && getModuleType(id) === "cjs") {
417
+ if (!isBuild && isCJSModule(id)) {
420
418
  const { ast } = await compiler.compile(source, id, {
421
419
  cache,
422
420
  ast: true,
@@ -650,30 +648,25 @@ function isEmpty(obj) {
650
648
  }
651
649
  return true;
652
650
  }
653
- function findPackageJson(file, root = process.cwd()) {
654
- let currentDir = import_path.default.dirname(file);
655
- while (currentDir !== root && currentDir.length > root.length) {
656
- const pkgPath = import_path.default.join(currentDir, "package.json");
657
- if (import_fs.default.existsSync(pkgPath)) {
658
- return pkgPath;
659
- }
660
- currentDir = import_path.default.dirname(currentDir);
661
- }
662
- return null;
663
- }
664
- const moduleTypeMap = /* @__PURE__ */ new Map();
665
- function getModuleType(file) {
666
- const pkgPath = findPackageJson(file);
667
- if (pkgPath) {
668
- let moduleType = moduleTypeMap.get(pkgPath);
669
- if (!moduleType) {
670
- const pkg = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf8"));
671
- moduleType = pkg.type === "module" || pkg.exports ? "esm" : "cjs";
672
- moduleTypeMap.set(pkgPath, moduleType);
651
+ const cjsModuleLookup = /* @__PURE__ */ new Map();
652
+ function isCJSModule(id) {
653
+ var _a;
654
+ const modulePath = (_a = /^.*[/\\]node_modules[/\\](?:@[^/\\]+[/\\])?[^/\\]+[/\\]/.exec(id)) == null ? void 0 : _a[0];
655
+ if (modulePath) {
656
+ let isCJS = cjsModuleLookup.get(modulePath);
657
+ if (isCJS === void 0) {
658
+ const pkgPath = modulePath + "package.json";
659
+ try {
660
+ const pkg = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf8"));
661
+ isCJS = pkg.type !== "module" && !pkg.exports;
662
+ } catch {
663
+ isCJS = false;
664
+ }
665
+ cjsModuleLookup.set(modulePath, isCJS);
673
666
  }
674
- return moduleType;
667
+ return isCJS;
675
668
  }
676
- return "esm";
669
+ return false;
677
670
  }
678
671
  function stripVersionAndTimeStamp(id) {
679
672
  const queryStart = id.indexOf("?");
package/dist/index.mjs CHANGED
@@ -56,10 +56,8 @@ function markoPlugin(opts = {}) {
56
56
  let domConfig;
57
57
  let hydrateConfig;
58
58
  const resolveVirtualDependency = (from, dep) => {
59
- const query = `${virtualFileQuery}&id=${encodeURIComponent(
60
- normalizePath(dep.virtualPath)
61
- )}`;
62
59
  const normalizedFrom = normalizePath(from);
60
+ const query = `${virtualFileQuery}&id=${Buffer.from(dep.virtualPath).toString("base64url") + path.extname(dep.virtualPath)}`;
63
61
  const id = normalizePath(normalizedFrom) + query;
64
62
  if (devServer) {
65
63
  const prev = virtualFiles.get(id);
@@ -396,7 +394,7 @@ function markoPlugin(opts = {}) {
396
394
  cachedSources.set(id, source);
397
395
  }
398
396
  if (!query) {
399
- if (!isBuild && /[\\/]node_modules[\\/]/.test(id) && getModuleType(id) === "cjs") {
397
+ if (!isBuild && isCJSModule(id)) {
400
398
  const { ast } = await compiler.compile(source, id, {
401
399
  cache,
402
400
  ast: true,
@@ -630,30 +628,25 @@ function isEmpty(obj) {
630
628
  }
631
629
  return true;
632
630
  }
633
- function findPackageJson(file, root = process.cwd()) {
634
- let currentDir = path.dirname(file);
635
- while (currentDir !== root && currentDir.length > root.length) {
636
- const pkgPath = path.join(currentDir, "package.json");
637
- if (fs.existsSync(pkgPath)) {
638
- return pkgPath;
639
- }
640
- currentDir = path.dirname(currentDir);
641
- }
642
- return null;
643
- }
644
- var moduleTypeMap = /* @__PURE__ */ new Map();
645
- function getModuleType(file) {
646
- const pkgPath = findPackageJson(file);
647
- if (pkgPath) {
648
- let moduleType = moduleTypeMap.get(pkgPath);
649
- if (!moduleType) {
650
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
651
- moduleType = pkg.type === "module" || pkg.exports ? "esm" : "cjs";
652
- moduleTypeMap.set(pkgPath, moduleType);
631
+ var cjsModuleLookup = /* @__PURE__ */ new Map();
632
+ function isCJSModule(id) {
633
+ var _a;
634
+ const modulePath = (_a = /^.*[/\\]node_modules[/\\](?:@[^/\\]+[/\\])?[^/\\]+[/\\]/.exec(id)) == null ? void 0 : _a[0];
635
+ if (modulePath) {
636
+ let isCJS = cjsModuleLookup.get(modulePath);
637
+ if (isCJS === void 0) {
638
+ const pkgPath = modulePath + "package.json";
639
+ try {
640
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
641
+ isCJS = pkg.type !== "module" && !pkg.exports;
642
+ } catch {
643
+ isCJS = false;
644
+ }
645
+ cjsModuleLookup.set(modulePath, isCJS);
653
646
  }
654
- return moduleType;
647
+ return isCJS;
655
648
  }
656
- return "esm";
649
+ return false;
657
650
  }
658
651
  function stripVersionAndTimeStamp(id) {
659
652
  const queryStart = id.indexOf("?");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/vite",
3
3
  "description": "A Marko plugin for Vite",
4
- "version": "3.1.2",
4
+ "version": "3.1.4",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {