@intlify/unplugin-vue-i18n 5.0.0-beta.2 → 5.0.0-beta.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/lib/index.cjs CHANGED
@@ -4,11 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const unplugin$1 = require('unplugin');
6
6
  const createDebug = require('debug');
7
- const fs = require('node:fs');
8
7
  const pc = require('picocolors');
9
- const module$1 = require('node:module');
10
8
  const path = require('node:path');
9
+ const fs = require('node:fs');
10
+ const module$1 = require('node:module');
11
11
  const pathe = require('pathe');
12
+ const mlly = require('mlly');
12
13
  const shared = require('@intlify/shared');
13
14
  const fg = require('fast-glob');
14
15
  const pluginutils = require('@rollup/pluginutils');
@@ -23,52 +24,27 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
23
24
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
24
25
 
25
26
  const createDebug__default = /*#__PURE__*/_interopDefaultCompat(createDebug);
26
- const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
27
27
  const pc__default = /*#__PURE__*/_interopDefaultCompat(pc);
28
- const module__default = /*#__PURE__*/_interopDefaultCompat(module$1);
29
28
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
29
+ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
30
+ const module__default = /*#__PURE__*/_interopDefaultCompat(module$1);
30
31
  const fg__default = /*#__PURE__*/_interopDefaultCompat(fg);
31
32
  const eslintUitls__default = /*#__PURE__*/_interopDefaultCompat(eslintUitls);
32
33
 
33
- const _require = module__default.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
34
- function checkInstallPackage(debug) {
35
- const pkgInfo = resolvePkgPath("vue-i18n", debug) || resolvePkgPath("petite-vue-i18n", debug);
36
- if (!pkgInfo) {
37
- throw new Error(
38
- `requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
39
- );
40
- }
41
- debug("installed package info:", pkgInfo);
42
- return pkgInfo;
43
- }
44
- function resolvePkgPath(id, debug) {
45
- try {
46
- const resolvedPath = _require.resolve(id);
47
- const pkgPath = path__default.dirname(resolvedPath);
48
- const pkgJson = JSON.parse(
49
- fs__default.readFileSync(path__default.join(pkgPath, "package.json"), "utf-8")
50
- );
51
- const pkgName = pkgJson.name.startsWith("vue-i18n") ? "vue-i18n" : pkgJson.name.startsWith("petite-vue-i18n") ? "petite-vue-i18n" : "";
52
- return pkgJson ? { alias: id, pkg: pkgName } : null;
53
- } catch (e) {
54
- debug(`cannot find '${id}'`, e);
55
- return null;
56
- }
57
- }
58
- function resolveNamespace(name) {
59
- return `unplugin-vue-i18n:${name}`;
60
- }
34
+ const PKG_NAME = "unplugin-vue-i18n";
35
+
61
36
  function warn(...args) {
62
- console.warn(pc__default.yellow(pc__default.bold(`[unplugin-vue-i18n] `)), ...args);
37
+ console.warn(pc__default.yellow(pc__default.bold(`[${PKG_NAME}] `)), ...args);
63
38
  }
64
39
  function error(...args) {
65
- console.error(pc__default.red(pc__default.bold(`[unplugin-vue-i18n] `)), ...args);
66
- }
67
- async function getRaw(path2) {
68
- return fs.promises.readFile(path2, { encoding: "utf-8" });
40
+ console.error(pc__default.red(pc__default.bold(`[${PKG_NAME}] `)), ...args);
69
41
  }
70
42
  function raiseError(message) {
71
- throw new Error(`[unplugin-vue-i18n] ${message}`);
43
+ throw new Error(`[${PKG_NAME}] ${message}`);
44
+ }
45
+
46
+ function resolveNamespace(name) {
47
+ return `${PKG_NAME}:${name}`;
72
48
  }
73
49
  function getVitePlugin(config, name) {
74
50
  return config.plugins.find((p) => p.name === name);
@@ -91,6 +67,92 @@ function normalizePath(id) {
91
67
  return path__default.posix.normalize(isWindows ? slash(id) : id);
92
68
  }
93
69
 
70
+ const defaultFindOptions = {
71
+ startingFrom: ".",
72
+ rootPattern: /^node_modules$/,
73
+ reverse: false,
74
+ test: (filePath) => {
75
+ try {
76
+ if (fs.statSync(filePath).isFile()) {
77
+ return true;
78
+ }
79
+ } catch {
80
+ }
81
+ }
82
+ };
83
+ function findFile(filename, _options = {}) {
84
+ const filenames = Array.isArray(filename) ? filename : [filename];
85
+ const options = { ...defaultFindOptions, ..._options };
86
+ const basePath = pathe.resolve(options.startingFrom);
87
+ const leadingSlash = basePath[0] === "/";
88
+ const segments = basePath.split("/").filter(Boolean);
89
+ if (leadingSlash) {
90
+ segments[0] = "/" + segments[0];
91
+ }
92
+ let root = segments.findIndex((r) => r.match(options.rootPattern));
93
+ if (root === -1) {
94
+ root = 0;
95
+ }
96
+ if (options.reverse) {
97
+ for (let index = root + 1; index <= segments.length; index++) {
98
+ for (const filename2 of filenames) {
99
+ const filePath = pathe.join(...segments.slice(0, index), filename2);
100
+ if (options.test(filePath)) {
101
+ return filePath;
102
+ }
103
+ }
104
+ }
105
+ } else {
106
+ for (let index = segments.length; index > root; index--) {
107
+ for (const filename2 of filenames) {
108
+ const filePath = pathe.join(...segments.slice(0, index), filename2);
109
+ if (options.test(filePath)) {
110
+ return filePath;
111
+ }
112
+ }
113
+ }
114
+ }
115
+ throw new Error(
116
+ `Cannot find matching ${filename} in ${options.startingFrom} or parent directories`
117
+ );
118
+ }
119
+ function findNearestFile(filename, _options = {}) {
120
+ return findFile(filename, _options);
121
+ }
122
+ function resolvePackageJSON(id = process.cwd(), options = {}) {
123
+ const resolvedPath = pathe.isAbsolute(id) ? id : mlly.resolvePathSync(id, options);
124
+ return findNearestFile("package.json", {
125
+ startingFrom: resolvedPath,
126
+ ...options
127
+ });
128
+ }
129
+
130
+ const _require = module__default.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
131
+ function checkInstallPackage(debug) {
132
+ const pkgInfo = resolvePkgPath("vue-i18n", debug) || resolvePkgPath("petite-vue-i18n", debug);
133
+ if (!pkgInfo) {
134
+ throw new Error(
135
+ `requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
136
+ );
137
+ }
138
+ debug("installed package info:", pkgInfo);
139
+ return pkgInfo;
140
+ }
141
+ function resolvePkgPath(id, debug) {
142
+ try {
143
+ const modPath = _require.resolve(id);
144
+ debug("modPath:", modPath, id);
145
+ const pkgJsonPath = resolvePackageJSON(modPath);
146
+ debug("pkgJsonPath:", pkgJsonPath);
147
+ const pkgJson = JSON.parse(fs__default.readFileSync(pkgJsonPath, "utf-8"));
148
+ const pkgName = pkgJson.name.startsWith("vue-i18n") ? "vue-i18n" : pkgJson.name.startsWith("petite-vue-i18n") ? "petite-vue-i18n" : "";
149
+ return pkgJson ? { alias: id, pkg: pkgName } : null;
150
+ } catch (e) {
151
+ debug(`cannot find '${id}'`, e);
152
+ return null;
153
+ }
154
+ }
155
+
94
156
  function resolveOptions(options, installedPkgInfo) {
95
157
  let onlyLocales = [];
96
158
  if (options.onlyLocales) {
@@ -704,6 +766,9 @@ function getVirtualId(id, framework = "vite") {
704
766
  function asVirtualId(id, framework = "vite") {
705
767
  return framework === "vite" ? VIRTUAL_PREFIX + id : id;
706
768
  }
769
+ async function getRaw(path) {
770
+ return fs.promises.readFile(path, { encoding: "utf-8" });
771
+ }
707
772
 
708
773
  const debug$1 = createDebug__default(resolveNamespace("directive"));
709
774
  function directivePlugin({
package/lib/index.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  import { createUnplugin } from 'unplugin';
2
2
  import createDebug from 'debug';
3
- import fs, { promises } from 'node:fs';
4
3
  import pc from 'picocolors';
5
- import module from 'node:module';
6
4
  import path from 'node:path';
7
- import { normalize, parse } from 'pathe';
5
+ import fs, { statSync, promises } from 'node:fs';
6
+ import module from 'node:module';
7
+ import { isAbsolute, resolve, join, normalize, parse } from 'pathe';
8
+ import { resolvePathSync } from 'mlly';
8
9
  import { isArray, isString, isBoolean, assign, isNumber, isEmptyObject, generateCodeFrame } from '@intlify/shared';
9
10
  import fg from 'fast-glob';
10
11
  import { createFilter } from '@rollup/pluginutils';
@@ -15,45 +16,20 @@ import { analyze } from '@typescript-eslint/scope-manager';
15
16
  import { parse as parse$2, simpleTraverse, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
16
17
  import eslintUitls from '@eslint-community/eslint-utils';
17
18
 
18
- const _require = module.createRequire(import.meta.url);
19
- function checkInstallPackage(debug) {
20
- const pkgInfo = resolvePkgPath("vue-i18n", debug) || resolvePkgPath("petite-vue-i18n", debug);
21
- if (!pkgInfo) {
22
- throw new Error(
23
- `requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
24
- );
25
- }
26
- debug("installed package info:", pkgInfo);
27
- return pkgInfo;
28
- }
29
- function resolvePkgPath(id, debug) {
30
- try {
31
- const resolvedPath = _require.resolve(id);
32
- const pkgPath = path.dirname(resolvedPath);
33
- const pkgJson = JSON.parse(
34
- fs.readFileSync(path.join(pkgPath, "package.json"), "utf-8")
35
- );
36
- const pkgName = pkgJson.name.startsWith("vue-i18n") ? "vue-i18n" : pkgJson.name.startsWith("petite-vue-i18n") ? "petite-vue-i18n" : "";
37
- return pkgJson ? { alias: id, pkg: pkgName } : null;
38
- } catch (e) {
39
- debug(`cannot find '${id}'`, e);
40
- return null;
41
- }
42
- }
43
- function resolveNamespace(name) {
44
- return `unplugin-vue-i18n:${name}`;
45
- }
19
+ const PKG_NAME = "unplugin-vue-i18n";
20
+
46
21
  function warn(...args) {
47
- console.warn(pc.yellow(pc.bold(`[unplugin-vue-i18n] `)), ...args);
22
+ console.warn(pc.yellow(pc.bold(`[${PKG_NAME}] `)), ...args);
48
23
  }
49
24
  function error(...args) {
50
- console.error(pc.red(pc.bold(`[unplugin-vue-i18n] `)), ...args);
51
- }
52
- async function getRaw(path2) {
53
- return promises.readFile(path2, { encoding: "utf-8" });
25
+ console.error(pc.red(pc.bold(`[${PKG_NAME}] `)), ...args);
54
26
  }
55
27
  function raiseError(message) {
56
- throw new Error(`[unplugin-vue-i18n] ${message}`);
28
+ throw new Error(`[${PKG_NAME}] ${message}`);
29
+ }
30
+
31
+ function resolveNamespace(name) {
32
+ return `${PKG_NAME}:${name}`;
57
33
  }
58
34
  function getVitePlugin(config, name) {
59
35
  return config.plugins.find((p) => p.name === name);
@@ -76,6 +52,92 @@ function normalizePath(id) {
76
52
  return path.posix.normalize(isWindows ? slash(id) : id);
77
53
  }
78
54
 
55
+ const defaultFindOptions = {
56
+ startingFrom: ".",
57
+ rootPattern: /^node_modules$/,
58
+ reverse: false,
59
+ test: (filePath) => {
60
+ try {
61
+ if (statSync(filePath).isFile()) {
62
+ return true;
63
+ }
64
+ } catch {
65
+ }
66
+ }
67
+ };
68
+ function findFile(filename, _options = {}) {
69
+ const filenames = Array.isArray(filename) ? filename : [filename];
70
+ const options = { ...defaultFindOptions, ..._options };
71
+ const basePath = resolve(options.startingFrom);
72
+ const leadingSlash = basePath[0] === "/";
73
+ const segments = basePath.split("/").filter(Boolean);
74
+ if (leadingSlash) {
75
+ segments[0] = "/" + segments[0];
76
+ }
77
+ let root = segments.findIndex((r) => r.match(options.rootPattern));
78
+ if (root === -1) {
79
+ root = 0;
80
+ }
81
+ if (options.reverse) {
82
+ for (let index = root + 1; index <= segments.length; index++) {
83
+ for (const filename2 of filenames) {
84
+ const filePath = join(...segments.slice(0, index), filename2);
85
+ if (options.test(filePath)) {
86
+ return filePath;
87
+ }
88
+ }
89
+ }
90
+ } else {
91
+ for (let index = segments.length; index > root; index--) {
92
+ for (const filename2 of filenames) {
93
+ const filePath = join(...segments.slice(0, index), filename2);
94
+ if (options.test(filePath)) {
95
+ return filePath;
96
+ }
97
+ }
98
+ }
99
+ }
100
+ throw new Error(
101
+ `Cannot find matching ${filename} in ${options.startingFrom} or parent directories`
102
+ );
103
+ }
104
+ function findNearestFile(filename, _options = {}) {
105
+ return findFile(filename, _options);
106
+ }
107
+ function resolvePackageJSON(id = process.cwd(), options = {}) {
108
+ const resolvedPath = isAbsolute(id) ? id : resolvePathSync(id, options);
109
+ return findNearestFile("package.json", {
110
+ startingFrom: resolvedPath,
111
+ ...options
112
+ });
113
+ }
114
+
115
+ const _require = module.createRequire(import.meta.url);
116
+ function checkInstallPackage(debug) {
117
+ const pkgInfo = resolvePkgPath("vue-i18n", debug) || resolvePkgPath("petite-vue-i18n", debug);
118
+ if (!pkgInfo) {
119
+ throw new Error(
120
+ `requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
121
+ );
122
+ }
123
+ debug("installed package info:", pkgInfo);
124
+ return pkgInfo;
125
+ }
126
+ function resolvePkgPath(id, debug) {
127
+ try {
128
+ const modPath = _require.resolve(id);
129
+ debug("modPath:", modPath, id);
130
+ const pkgJsonPath = resolvePackageJSON(modPath);
131
+ debug("pkgJsonPath:", pkgJsonPath);
132
+ const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
133
+ const pkgName = pkgJson.name.startsWith("vue-i18n") ? "vue-i18n" : pkgJson.name.startsWith("petite-vue-i18n") ? "petite-vue-i18n" : "";
134
+ return pkgJson ? { alias: id, pkg: pkgName } : null;
135
+ } catch (e) {
136
+ debug(`cannot find '${id}'`, e);
137
+ return null;
138
+ }
139
+ }
140
+
79
141
  function resolveOptions(options, installedPkgInfo) {
80
142
  let onlyLocales = [];
81
143
  if (options.onlyLocales) {
@@ -689,6 +751,9 @@ function getVirtualId(id, framework = "vite") {
689
751
  function asVirtualId(id, framework = "vite") {
690
752
  return framework === "vite" ? VIRTUAL_PREFIX + id : id;
691
753
  }
754
+ async function getRaw(path) {
755
+ return promises.readFile(path, { encoding: "utf-8" });
756
+ }
692
757
 
693
758
  const debug$1 = createDebug(resolveNamespace("directive"));
694
759
  function directivePlugin({
package/lib/vite.cjs CHANGED
@@ -3,11 +3,12 @@
3
3
  const index = require('./index.cjs');
4
4
  require('unplugin');
5
5
  require('debug');
6
- require('node:fs');
7
6
  require('picocolors');
8
- require('node:module');
9
7
  require('node:path');
8
+ require('node:fs');
9
+ require('node:module');
10
10
  require('pathe');
11
+ require('mlly');
11
12
  require('@intlify/shared');
12
13
  require('fast-glob');
13
14
  require('@rollup/pluginutils');
package/lib/vite.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  import { unplugin } from './index.mjs';
2
2
  import 'unplugin';
3
3
  import 'debug';
4
- import 'node:fs';
5
4
  import 'picocolors';
6
- import 'node:module';
7
5
  import 'node:path';
6
+ import 'node:fs';
7
+ import 'node:module';
8
8
  import 'pathe';
9
+ import 'mlly';
9
10
  import '@intlify/shared';
10
11
  import 'fast-glob';
11
12
  import '@rollup/pluginutils';
package/lib/webpack.cjs CHANGED
@@ -3,11 +3,12 @@
3
3
  const index = require('./index.cjs');
4
4
  require('unplugin');
5
5
  require('debug');
6
- require('node:fs');
7
6
  require('picocolors');
8
- require('node:module');
9
7
  require('node:path');
8
+ require('node:fs');
9
+ require('node:module');
10
10
  require('pathe');
11
+ require('mlly');
11
12
  require('@intlify/shared');
12
13
  require('fast-glob');
13
14
  require('@rollup/pluginutils');
package/lib/webpack.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  import { unplugin } from './index.mjs';
2
2
  import 'unplugin';
3
3
  import 'debug';
4
- import 'node:fs';
5
4
  import 'picocolors';
6
- import 'node:module';
7
5
  import 'node:path';
6
+ import 'node:fs';
7
+ import 'node:module';
8
8
  import 'pathe';
9
+ import 'mlly';
9
10
  import '@intlify/shared';
10
11
  import 'fast-glob';
11
12
  import '@rollup/pluginutils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/unplugin-vue-i18n",
3
- "version": "5.0.0-beta.2",
3
+ "version": "5.0.0-beta.3",
4
4
  "description": "unplugin for Vue I18n",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
@@ -34,6 +34,7 @@
34
34
  "fast-glob": "^3.2.12",
35
35
  "js-yaml": "^4.1.0",
36
36
  "json5": "^2.2.3",
37
+ "mlly": "^1.7.1",
37
38
  "pathe": "^1.0.0",
38
39
  "picocolors": "^1.0.0",
39
40
  "source-map-js": "^1.0.2",