@marko/vite 3.1.1 → 3.1.3

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
@@ -416,7 +416,7 @@ function markoPlugin(opts = {}) {
416
416
  cachedSources.set(id, source);
417
417
  }
418
418
  if (!query) {
419
- if (/[\\/]node_modules[\\/]/.test(id) && getModuleType(id) === "cjs") {
419
+ if (!isBuild && isCJSModule(id)) {
420
420
  const { ast } = await compiler.compile(source, id, {
421
421
  cache,
422
422
  ast: true,
@@ -650,30 +650,25 @@ function isEmpty(obj) {
650
650
  }
651
651
  return true;
652
652
  }
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);
653
+ const cjsModuleLookup = /* @__PURE__ */ new Map();
654
+ function isCJSModule(id) {
655
+ var _a;
656
+ const modulePath = (_a = /^.*[/\\]node_modules[/\\](?:@[^/\\]+[/\\])?[^/\\]+[/\\]/.exec(id)) == null ? void 0 : _a[0];
657
+ if (modulePath) {
658
+ let isCJS = cjsModuleLookup.get(modulePath);
659
+ if (isCJS === void 0) {
660
+ const pkgPath = modulePath + "package.json";
661
+ try {
662
+ const pkg = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf8"));
663
+ isCJS = pkg.type !== "module" && !pkg.exports;
664
+ } catch {
665
+ isCJS = false;
666
+ }
667
+ cjsModuleLookup.set(modulePath, isCJS);
673
668
  }
674
- return moduleType;
669
+ return isCJS;
675
670
  }
676
- return "esm";
671
+ return false;
677
672
  }
678
673
  function stripVersionAndTimeStamp(id) {
679
674
  const queryStart = id.indexOf("?");
package/dist/index.mjs CHANGED
@@ -396,7 +396,7 @@ function markoPlugin(opts = {}) {
396
396
  cachedSources.set(id, source);
397
397
  }
398
398
  if (!query) {
399
- if (/[\\/]node_modules[\\/]/.test(id) && getModuleType(id) === "cjs") {
399
+ if (!isBuild && isCJSModule(id)) {
400
400
  const { ast } = await compiler.compile(source, id, {
401
401
  cache,
402
402
  ast: true,
@@ -630,30 +630,25 @@ function isEmpty(obj) {
630
630
  }
631
631
  return true;
632
632
  }
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);
633
+ var cjsModuleLookup = /* @__PURE__ */ new Map();
634
+ function isCJSModule(id) {
635
+ var _a;
636
+ const modulePath = (_a = /^.*[/\\]node_modules[/\\](?:@[^/\\]+[/\\])?[^/\\]+[/\\]/.exec(id)) == null ? void 0 : _a[0];
637
+ if (modulePath) {
638
+ let isCJS = cjsModuleLookup.get(modulePath);
639
+ if (isCJS === void 0) {
640
+ const pkgPath = modulePath + "package.json";
641
+ try {
642
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
643
+ isCJS = pkg.type !== "module" && !pkg.exports;
644
+ } catch {
645
+ isCJS = false;
646
+ }
647
+ cjsModuleLookup.set(modulePath, isCJS);
653
648
  }
654
- return moduleType;
649
+ return isCJS;
655
650
  }
656
- return "esm";
651
+ return false;
657
652
  }
658
653
  function stripVersionAndTimeStamp(id) {
659
654
  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.1",
4
+ "version": "3.1.3",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {