@intlify/bundle-utils 2.2.1 → 3.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/CHANGELOG.md CHANGED
@@ -1,4 +1,31 @@
1
1
 
2
+ ## @intlify/bundle-utils@3.1.0 (2022-05-06)
3
+
4
+ #### :zap: Improvement Features
5
+ * [#116](https://github.com/intlify/bundle-tools/pull/116) improvement(bundle-utils): support ESM exporting on bridge ([@kazupon](https://github.com/kazupon))
6
+
7
+ #### Committers: 1
8
+ - kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
9
+
10
+
11
+ ## @intlify/bundle-utils@3.0.0 (2022-04-05)
12
+
13
+ #### :star: Features
14
+ * [#101](https://github.com/intlify/bundle-tools/pull/101) feat(bundle-utils): pinned intlify related module next version ([@kazupon](https://github.com/kazupon))
15
+
16
+ #### Committers: 1
17
+ - kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
18
+
19
+
20
+ ## @intlify/bundle-utils@2.2.2 (2022-04-05)
21
+
22
+ #### :zap: Improvement Features
23
+ * [#100](https://github.com/intlify/bundle-tools/pull/100) fix(bundle-utils): pinned latest stable version ([@kazupon](https://github.com/kazupon))
24
+
25
+ #### Committers: 1
26
+ - kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
27
+
28
+
2
29
  ## @intlify/bundle-utils@2.2.1 (2022-03-22)
3
30
 
4
31
  #### :bug: Bug Fixes
package/lib/codegen.d.ts CHANGED
@@ -24,6 +24,7 @@ export interface SourceLocationable {
24
24
  export interface CodeGenOptions {
25
25
  type?: 'plain' | 'sfc' | 'bare';
26
26
  bridge?: boolean;
27
+ exportESM?: boolean;
27
28
  source?: string;
28
29
  sourceMap?: boolean;
29
30
  filename?: string;
package/lib/codegen.js CHANGED
@@ -102,7 +102,7 @@ function generateMessageFunction(msg, options) {
102
102
  options.onError && options.onError(err.message);
103
103
  occured = true;
104
104
  };
105
- const { code, ast, map } = message_compiler_1.baseCompile(msg, newOptions);
105
+ const { code, ast, map } = (0, message_compiler_1.baseCompile)(msg, newOptions);
106
106
  const genCode = !occured
107
107
  ? env === 'development'
108
108
  ? `(()=>{const fn=${code};fn.source=${JSON.stringify(msg)};return fn;})()`
package/lib/json.d.ts CHANGED
@@ -7,4 +7,4 @@ import type { CodeGenOptions, CodeGenResult } from './codegen';
7
7
  /**
8
8
  * @internal
9
9
  */
10
- export declare function generate(targetSource: string | Buffer, { type, bridge, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, useClassComponent }: CodeGenOptions, injector?: () => string): CodeGenResult<JSONProgram>;
10
+ export declare function generate(targetSource: string | Buffer, { type, bridge, exportESM, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, useClassComponent }: CodeGenOptions, injector?: () => string): CodeGenResult<JSONProgram>;
package/lib/json.js CHANGED
@@ -10,7 +10,7 @@ const codegen_1 = require("./codegen");
10
10
  /**
11
11
  * @internal
12
12
  */
13
- function generate(targetSource, { type = 'plain', bridge = false, filename = 'vue-i18n-loader.json', inSourceMap = undefined, locale = '', isGlobal = false, sourceMap = false, env = 'development', forceStringify = false, useClassComponent = false }, injector) {
13
+ function generate(targetSource, { type = 'plain', bridge = false, exportESM = false, filename = 'vue-i18n-loader.json', inSourceMap = undefined, locale = '', isGlobal = false, sourceMap = false, env = 'development', forceStringify = false, useClassComponent = false }, injector) {
14
14
  const target = Buffer.isBuffer(targetSource)
15
15
  ? targetSource.toString()
16
16
  : targetSource;
@@ -21,6 +21,7 @@ function generate(targetSource, { type = 'plain', bridge = false, filename = 'vu
21
21
  const options = {
22
22
  type,
23
23
  bridge,
24
+ exportESM,
24
25
  source: value,
25
26
  sourceMap,
26
27
  locale,
@@ -31,8 +32,8 @@ function generate(targetSource, { type = 'plain', bridge = false, filename = 'vu
31
32
  forceStringify,
32
33
  useClassComponent
33
34
  };
34
- const generator = codegen_1.createCodeGenerator(options);
35
- const ast = jsonc_eslint_parser_1.parseJSON(value, { filePath: filename });
35
+ const generator = (0, codegen_1.createCodeGenerator)(options);
36
+ const ast = (0, jsonc_eslint_parser_1.parseJSON)(value, { filePath: filename });
36
37
  const codeMaps = generateNode(generator, ast, options, injector);
37
38
  const { code, map } = generator.context();
38
39
  // if (map) {
@@ -43,7 +44,7 @@ function generate(targetSource, { type = 'plain', bridge = false, filename = 'vu
43
44
  // }
44
45
  // prettier-ignore
45
46
  const newMap = map
46
- ? codegen_1.mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null // eslint-disable-line @typescript-eslint/no-explicit-any
47
+ ? (0, codegen_1.mapLinesColumns)(map.toJSON(), codeMaps, inSourceMap) || null // eslint-disable-line @typescript-eslint/no-explicit-any
47
48
  : null;
48
49
  return {
49
50
  ast,
@@ -57,13 +58,14 @@ function generateNode(generator, node, options, injector) {
57
58
  const itemsCountStack = [];
58
59
  const { forceStringify } = generator.context();
59
60
  const codeMaps = new Map();
60
- const { type, bridge, sourceMap, isGlobal, locale, useClassComponent } = options;
61
+ const { type, bridge, exportESM, sourceMap, isGlobal, locale, useClassComponent } = options;
62
+ // prettier-ignore
61
63
  const componentNamespace = bridge
62
64
  ? `Component.options`
63
65
  : useClassComponent
64
66
  ? `Component.__o`
65
67
  : `Component`;
66
- jsonc_eslint_parser_1.traverseNodes(node, {
68
+ (0, jsonc_eslint_parser_1.traverseNodes)(node, {
67
69
  enterNode(node, parent) {
68
70
  switch (node.type) {
69
71
  case 'Program':
@@ -74,7 +76,11 @@ function generateNode(generator, node, options, injector) {
74
76
  // for 'sfc'
75
77
  const variableName = type === 'sfc' ? (!isGlobal ? '__i18n' : '__i18nGlobal') : '';
76
78
  const localeName = type === 'sfc' ? (locale != null ? locale : `""`) : '';
77
- const exportSyntax = bridge ? `module.exports =` : `export default`;
79
+ const exportSyntax = bridge
80
+ ? exportESM
81
+ ? `export default`
82
+ : `module.exports =`
83
+ : `export default`;
78
84
  generator.push(`${exportSyntax} function (Component) {`);
79
85
  generator.indent();
80
86
  generator.pushline(`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`);
@@ -99,9 +105,9 @@ function generateNode(generator, node, options, injector) {
99
105
  node.key.type === 'JSONIdentifier')) {
100
106
  const name = node.key.type === 'JSONLiteral' ? node.key.value : node.key.name;
101
107
  const value = node.value.value;
102
- if (shared_1.isString(value)) {
108
+ if ((0, shared_1.isString)(value)) {
103
109
  generator.push(`${JSON.stringify(name)}: `);
104
- const { code, map } = codegen_1.generateMessageFunction(value, options);
110
+ const { code, map } = (0, codegen_1.generateMessageFunction)(value, options);
105
111
  sourceMap && map != null && codeMaps.set(value, map);
106
112
  generator.push(`${code}`, node.value, value);
107
113
  }
@@ -109,7 +115,7 @@ function generateNode(generator, node, options, injector) {
109
115
  if (forceStringify) {
110
116
  const strValue = JSON.stringify(value);
111
117
  generator.push(`${JSON.stringify(name)}: `);
112
- const { code, map } = codegen_1.generateMessageFunction(strValue, options);
118
+ const { code, map } = (0, codegen_1.generateMessageFunction)(strValue, options);
113
119
  sourceMap && map != null && codeMaps.set(strValue, map);
114
120
  generator.push(`${code}`, node.value, strValue);
115
121
  }
@@ -137,15 +143,15 @@ function generateNode(generator, node, options, injector) {
137
143
  if (parent.type === 'JSONArrayExpression') {
138
144
  if (node.type === 'JSONLiteral') {
139
145
  const value = node.value;
140
- if (shared_1.isString(value)) {
141
- const { code, map } = codegen_1.generateMessageFunction(value, options);
146
+ if ((0, shared_1.isString)(value)) {
147
+ const { code, map } = (0, codegen_1.generateMessageFunction)(value, options);
142
148
  sourceMap && map != null && codeMaps.set(value, map);
143
149
  generator.push(`${code}`, node, value);
144
150
  }
145
151
  else {
146
152
  if (forceStringify) {
147
153
  const strValue = JSON.stringify(value);
148
- const { code, map } = codegen_1.generateMessageFunction(strValue, options);
154
+ const { code, map } = (0, codegen_1.generateMessageFunction)(strValue, options);
149
155
  sourceMap && map != null && codeMaps.set(strValue, map);
150
156
  generator.push(`${code}`, node, strValue);
151
157
  }
package/lib/yaml.d.ts CHANGED
@@ -7,4 +7,4 @@ import type { CodeGenOptions, CodeGenResult } from './codegen';
7
7
  /**
8
8
  * @internal
9
9
  */
10
- export declare function generate(targetSource: string | Buffer, { type, bridge, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify }: CodeGenOptions, injector?: () => string): CodeGenResult<YAMLProgram>;
10
+ export declare function generate(targetSource: string | Buffer, { type, bridge, exportESM, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify }: CodeGenOptions, injector?: () => string): CodeGenResult<YAMLProgram>;
package/lib/yaml.js CHANGED
@@ -10,13 +10,14 @@ const yaml_eslint_parser_1 = require("yaml-eslint-parser");
10
10
  /**
11
11
  * @internal
12
12
  */
13
- function generate(targetSource, { type = 'plain', bridge = false, useClassComponent = false, filename = 'vue-i18n-loader.yaml', inSourceMap = undefined, locale = '', isGlobal = false, sourceMap = false, env = 'development', forceStringify = false }, injector) {
13
+ function generate(targetSource, { type = 'plain', bridge = false, exportESM = false, useClassComponent = false, filename = 'vue-i18n-loader.yaml', inSourceMap = undefined, locale = '', isGlobal = false, sourceMap = false, env = 'development', forceStringify = false }, injector) {
14
14
  const value = Buffer.isBuffer(targetSource)
15
15
  ? targetSource.toString()
16
16
  : targetSource;
17
17
  const options = {
18
18
  type,
19
19
  bridge,
20
+ exportESM,
20
21
  source: value,
21
22
  sourceMap,
22
23
  locale,
@@ -27,13 +28,13 @@ function generate(targetSource, { type = 'plain', bridge = false, useClassCompon
27
28
  forceStringify,
28
29
  useClassComponent
29
30
  };
30
- const generator = codegen_1.createCodeGenerator(options);
31
- const ast = yaml_eslint_parser_1.parseYAML(value, { filePath: filename });
31
+ const generator = (0, codegen_1.createCodeGenerator)(options);
32
+ const ast = (0, yaml_eslint_parser_1.parseYAML)(value, { filePath: filename });
32
33
  const codeMaps = generateNode(generator, ast, options, injector);
33
34
  const { code, map } = generator.context();
34
35
  // prettier-ignore
35
36
  const newMap = map
36
- ? codegen_1.mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null // eslint-disable-line @typescript-eslint/no-explicit-any
37
+ ? (0, codegen_1.mapLinesColumns)(map.toJSON(), codeMaps, inSourceMap) || null // eslint-disable-line @typescript-eslint/no-explicit-any
37
38
  : null;
38
39
  return {
39
40
  ast,
@@ -47,13 +48,14 @@ function generateNode(generator, node, options, injector) {
47
48
  const itemsCountStack = [];
48
49
  const { forceStringify } = generator.context();
49
50
  const codeMaps = new Map();
50
- const { type, bridge, sourceMap, isGlobal, locale, useClassComponent } = options;
51
+ const { type, bridge, exportESM, sourceMap, isGlobal, locale, useClassComponent } = options;
52
+ // prettier-ignore
51
53
  const componentNamespace = bridge
52
54
  ? `Component.options`
53
55
  : useClassComponent
54
56
  ? `Component.__o`
55
57
  : `Component`;
56
- yaml_eslint_parser_1.traverseNodes(node, {
58
+ (0, yaml_eslint_parser_1.traverseNodes)(node, {
57
59
  enterNode(node, parent) {
58
60
  switch (node.type) {
59
61
  case 'Program':
@@ -63,7 +65,11 @@ function generateNode(generator, node, options, injector) {
63
65
  else if (type === 'sfc') {
64
66
  const variableName = type === 'sfc' ? (!isGlobal ? '__i18n' : '__i18nGlobal') : '';
65
67
  const localeName = type === 'sfc' ? (locale != null ? locale : `""`) : '';
66
- const exportSyntax = bridge ? `module.exports =` : `export default`;
68
+ const exportSyntax = bridge
69
+ ? exportESM
70
+ ? `export default`
71
+ : `module.exports =`
72
+ : `export default`;
67
73
  generator.push(`${exportSyntax} function (Component) {`);
68
74
  generator.indent();
69
75
  generator.pushline(`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`);
@@ -89,9 +95,9 @@ function generateNode(generator, node, options, injector) {
89
95
  node.key.type === 'YAMLScalar') {
90
96
  const name = node.key.value;
91
97
  const value = node.value.value;
92
- if (shared_1.isString(value)) {
98
+ if ((0, shared_1.isString)(value)) {
93
99
  generator.push(`${JSON.stringify(name)}: `);
94
- const { code, map } = codegen_1.generateMessageFunction(value, options);
100
+ const { code, map } = (0, codegen_1.generateMessageFunction)(value, options);
95
101
  sourceMap && map != null && codeMaps.set(value, map);
96
102
  generator.push(`${code}`, node.value, value);
97
103
  }
@@ -99,7 +105,7 @@ function generateNode(generator, node, options, injector) {
99
105
  if (forceStringify) {
100
106
  const strValue = JSON.stringify(value);
101
107
  generator.push(`${JSON.stringify(name)}: `);
102
- const { code, map } = codegen_1.generateMessageFunction(strValue, options);
108
+ const { code, map } = (0, codegen_1.generateMessageFunction)(strValue, options);
103
109
  sourceMap && map != null && codeMaps.set(strValue, map);
104
110
  generator.push(`${code}`, node.value, strValue);
105
111
  }
@@ -128,15 +134,15 @@ function generateNode(generator, node, options, injector) {
128
134
  if (parent.type === 'YAMLSequence') {
129
135
  if (node.type === 'YAMLScalar') {
130
136
  const value = node.value;
131
- if (shared_1.isString(value)) {
132
- const { code, map } = codegen_1.generateMessageFunction(value, options);
137
+ if ((0, shared_1.isString)(value)) {
138
+ const { code, map } = (0, codegen_1.generateMessageFunction)(value, options);
133
139
  sourceMap && map != null && codeMaps.set(value, map);
134
140
  generator.push(`${code}`, node, value);
135
141
  }
136
142
  else {
137
143
  if (forceStringify) {
138
144
  const strValue = JSON.stringify(value);
139
- const { code, map } = codegen_1.generateMessageFunction(strValue, options);
145
+ const { code, map } = (0, codegen_1.generateMessageFunction)(strValue, options);
140
146
  sourceMap && map != null && codeMaps.set(strValue, map);
141
147
  generator.push(`${code}`, node, strValue);
142
148
  }
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": "2.2.1",
4
+ "version": "3.1.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -9,23 +9,21 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/intlify/bundle-tools/issues"
11
11
  },
12
- "peerDependencies": {},
13
12
  "peerDependenciesMeta": {
14
- "vue-i18n": {
13
+ "petite-vue-i18n": {
15
14
  "optional": true
16
15
  },
17
- "petite-vue-i18n": {
16
+ "vue-i18n": {
18
17
  "optional": true
19
18
  }
20
19
  },
21
20
  "dependencies": {
22
- "@intlify/message-compiler": "beta",
23
- "@intlify/shared": "beta",
21
+ "@intlify/message-compiler": "next",
22
+ "@intlify/shared": "next",
24
23
  "jsonc-eslint-parser": "^1.0.1",
25
- "source-map": "^0.6.1",
24
+ "source-map": "0.6.1",
26
25
  "yaml-eslint-parser": "^0.3.2"
27
26
  },
28
- "devDependencies": {},
29
27
  "engines": {
30
28
  "node": ">= 12"
31
29
  },
@@ -42,11 +40,11 @@
42
40
  },
43
41
  "scripts": {
44
42
  "build": "tsc -p .",
45
- "clean": "npm-run-all clean:*",
43
+ "clean": "npm-run-all \"clean:*\"",
46
44
  "clean:lib": "rm -rf ./lib",
47
45
  "watch": "tsc -p . --watch",
48
- "changelog": "esmo ../../scripts/changelog.ts",
49
- "release": "esmo ../../scripts/release.ts"
46
+ "changelog": "jiti ../../scripts/changelog.ts",
47
+ "release": "jiti ../../scripts/release.ts"
50
48
  },
51
49
  "types": "lib/index.d.ts"
52
50
  }