@intlify/bundle-utils 7.0.1 → 7.1.0

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
@@ -2,20 +2,20 @@
2
2
 
3
3
  const jsoncEslintParser = require('jsonc-eslint-parser');
4
4
  const shared = require('@intlify/shared');
5
- const module$1 = require('node:module');
6
5
  const sourceMapJs = require('source-map-js');
6
+ const messageCompiler = require('@intlify/message-compiler');
7
7
  const MagicString = require('magic-string');
8
8
  const yamlEslintParser = require('yaml-eslint-parser');
9
9
  const acorn = require('acorn');
10
10
  const escodegen = require('escodegen');
11
11
  const estreeWalker = require('estree-walker');
12
+ const module$1 = require('node:module');
13
+
14
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
15
+
16
+ const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
17
+ const module__default = /*#__PURE__*/_interopDefaultCompat(module$1);
12
18
 
13
- const require$1 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
14
- const {
15
- baseCompile,
16
- detectHtmlTag,
17
- LocationStub
18
- } = require$1("@intlify/message-compiler");
19
19
  function createCodeGenerator(options = {
20
20
  filename: "bundle.json",
21
21
  sourceMap: false,
@@ -38,7 +38,7 @@ function createCodeGenerator(options = {
38
38
  function push(code, node, name) {
39
39
  _context.code += code;
40
40
  if (_context.map && node) {
41
- if (node.loc && node.loc !== LocationStub) {
41
+ if (node.loc && node.loc !== messageCompiler.LOCATION_STUB) {
42
42
  addMapping(node.loc.start, name);
43
43
  }
44
44
  advancePositionWithSource(_context, code);
@@ -119,7 +119,7 @@ function generateMessageFunction(msg, options = {}, path) {
119
119
  const onError = options.onError || ON_ERROR_NOOP;
120
120
  const errors = [];
121
121
  let detecteHtmlInMsg = false;
122
- if (detectHtmlTag(msg)) {
122
+ if (messageCompiler.detectHtmlTag(msg)) {
123
123
  detecteHtmlInMsg = true;
124
124
  if (strictMessage) {
125
125
  const errMsg = shared.format(DETECT_MESSAGE, { msg });
@@ -144,7 +144,7 @@ function generateMessageFunction(msg, options = {}, path) {
144
144
  errors.push(err);
145
145
  }
146
146
  };
147
- const { code, ast, map } = baseCompile(_msg, newOptions);
147
+ const { code, ast, map } = messageCompiler.baseCompile(_msg, newOptions);
148
148
  const occured = errors.length > 0;
149
149
  const genCode = !occured ? env === "development" ? `(()=>{const fn=${code};fn.source=${JSON.stringify(msg)};return fn;})()` : `${code}` : `\`${_msg}\``;
150
150
  return { code: genCode, ast, map, errors };
@@ -222,7 +222,7 @@ function generateResourceAst(msg, options = {}, path) {
222
222
  const onError = options.onError || ON_ERROR_NOOP;
223
223
  const errors = [];
224
224
  let detecteHtmlInMsg = false;
225
- if (detectHtmlTag(msg)) {
225
+ if (messageCompiler.detectHtmlTag(msg)) {
226
226
  detecteHtmlInMsg = true;
227
227
  if (strictMessage) {
228
228
  const errMsg = shared.format(DETECT_MESSAGE, { msg });
@@ -234,7 +234,10 @@ function generateResourceAst(msg, options = {}, path) {
234
234
  }
235
235
  const _msg = detecteHtmlInMsg && escapeHtml ? shared.escapeHtml(msg) : msg;
236
236
  const newOptions = Object.assign(
237
- { location: env === "development" },
237
+ {
238
+ location: env === "development",
239
+ minify: shared.isBoolean(options.minify) ? options.minify : env === "production"
240
+ },
238
241
  options
239
242
  );
240
243
  if (newOptions.jit != null) {
@@ -253,7 +256,7 @@ function generateResourceAst(msg, options = {}, path) {
253
256
  errors.push(err);
254
257
  }
255
258
  };
256
- const { ast, map } = baseCompile(_msg, newOptions);
259
+ const { ast, map } = messageCompiler.baseCompile(_msg, newOptions);
257
260
  const occured = errors.length > 0;
258
261
  const code = !occured ? `${shared.friendlyJSONstringify(ast)}` : `\`${_msg}\``;
259
262
  return { code, ast, map, errors };
@@ -316,7 +319,7 @@ function generate$2(targetSource, {
316
319
  if (legacy && type === "sfc") {
317
320
  const gen = () => shared.friendlyJSONstringify(jsoncEslintParser.getStaticJSONValue(ast));
318
321
  const code2 = generateLegacyCode(options, gen);
319
- const s = new MagicString(code2);
322
+ const s = new MagicString__default(code2);
320
323
  return {
321
324
  ast,
322
325
  code: s.toString(),
@@ -575,7 +578,7 @@ function generate$1(targetSource, {
575
578
  if (legacy && type === "sfc") {
576
579
  const gen = () => shared.friendlyJSONstringify(yamlEslintParser.getStaticYAMLValue(ast));
577
580
  const code2 = generateLegacyCode(options, gen);
578
- const s = new MagicString(code2);
581
+ const s = new MagicString__default(code2);
579
582
  return {
580
583
  ast,
581
584
  code: s.toString(),
@@ -1146,7 +1149,7 @@ function getValue(node) {
1146
1149
  return node.type === "Literal" ? node.value : node.type === "TemplateLiteral" ? node.quasis.map((quasi) => quasi.value.cooked).join("") : void 0;
1147
1150
  }
1148
1151
 
1149
- const _require = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
1152
+ const _require = module__default.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
1150
1153
  function checkInstallPackage(pkg, debug) {
1151
1154
  let installedVueI18n = false;
1152
1155
  try {
package/lib/index.d.ts CHANGED
@@ -31,6 +31,7 @@ interface CodeGenOptions {
31
31
  strictMessage?: boolean;
32
32
  escapeHtml?: boolean;
33
33
  jit?: boolean;
34
+ minify?: boolean;
34
35
  onWarn?: (msg: string) => void;
35
36
  onError?: (msg: string, extra?: {
36
37
  source: string;
package/lib/index.mjs CHANGED
@@ -1,19 +1,14 @@
1
1
  import { parseJSON, traverseNodes, getStaticJSONValue } from 'jsonc-eslint-parser';
2
2
  import { isBoolean, format, escapeHtml, friendlyJSONstringify, isString, isNumber } from '@intlify/shared';
3
- import module from 'node:module';
4
3
  import { SourceMapGenerator, SourceMapConsumer } from 'source-map-js';
4
+ import { LOCATION_STUB, detectHtmlTag, baseCompile } from '@intlify/message-compiler';
5
5
  import MagicString from 'magic-string';
6
6
  import { parseYAML, traverseNodes as traverseNodes$1, getStaticYAMLValue } from 'yaml-eslint-parser';
7
7
  import { parse } from 'acorn';
8
8
  import { generate as generate$3 } from 'escodegen';
9
9
  import { walk } from 'estree-walker';
10
+ import module from 'node:module';
10
11
 
11
- const require = module.createRequire(import.meta.url);
12
- const {
13
- baseCompile,
14
- detectHtmlTag,
15
- LocationStub
16
- } = require("@intlify/message-compiler");
17
12
  function createCodeGenerator(options = {
18
13
  filename: "bundle.json",
19
14
  sourceMap: false,
@@ -36,7 +31,7 @@ function createCodeGenerator(options = {
36
31
  function push(code, node, name) {
37
32
  _context.code += code;
38
33
  if (_context.map && node) {
39
- if (node.loc && node.loc !== LocationStub) {
34
+ if (node.loc && node.loc !== LOCATION_STUB) {
40
35
  addMapping(node.loc.start, name);
41
36
  }
42
37
  advancePositionWithSource(_context, code);
@@ -232,7 +227,10 @@ function generateResourceAst(msg, options = {}, path) {
232
227
  }
233
228
  const _msg = detecteHtmlInMsg && escapeHtml$1 ? escapeHtml(msg) : msg;
234
229
  const newOptions = Object.assign(
235
- { location: env === "development" },
230
+ {
231
+ location: env === "development",
232
+ minify: isBoolean(options.minify) ? options.minify : env === "production"
233
+ },
236
234
  options
237
235
  );
238
236
  if (newOptions.jit != null) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@intlify/bundle-utils",
3
3
  "description": "Bundle utilities for Intlify project",
4
- "version": "7.0.1",
4
+ "version": "7.1.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -18,21 +18,21 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@intlify/message-compiler": "9.3.0-beta.20",
22
- "@intlify/shared": "9.3.0-beta.20",
21
+ "@intlify/message-compiler": "9.3.0-beta.27",
22
+ "@intlify/shared": "9.3.0-beta.27",
23
23
  "acorn": "^8.8.2",
24
24
  "escodegen": "^2.0.0",
25
25
  "estree-walker": "^2.0.2",
26
- "jsonc-eslint-parser": "^1.0.1",
26
+ "jsonc-eslint-parser": "^2.3.0",
27
27
  "magic-string": "^0.30.0",
28
28
  "mlly": "^1.2.0",
29
29
  "source-map-js": "^1.0.1",
30
- "yaml-eslint-parser": "^0.3.2"
30
+ "yaml-eslint-parser": "^1.2.2"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/escodegen": "^0.0.7",
34
34
  "@types/estree": "^1.0.0",
35
- "unbuild": "^1.1.2"
35
+ "unbuild": "^1.2.1"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">= 14.16"