@intlify/bundle-utils 2.0.0 → 2.2.1

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,40 @@
1
1
 
2
+ ## @intlify/bundle-utils@2.2.1 (2022-03-22)
3
+
4
+ #### :bug: Bug Fixes
5
+ * [#98](https://github.com/intlify/bundle-tools/pull/98) fix(bundle-utils): fix nested array code generation ([@kazupon](https://github.com/kazupon))
6
+
7
+ #### Committers: 1
8
+ - kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
9
+
10
+
11
+ ## @intlify/bundle-utils@2.2.1 (2022-03-22)
12
+
13
+ #### :bug: Bug Fixes
14
+ * [#98](https://github.com/intlify/bundle-tools/pull/98) fix(bundle-utils): fix nested array code generation ([@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.0 (2021-12-16)
21
+
22
+ #### :zap: Improvement Features
23
+ * [#75](https://github.com/intlify/bundle-tools/pull/75) Add vue-class-components support via loader option ([@SniperJoe](https://github.com/SniperJoe))
24
+
25
+ #### Committers: 1
26
+ - [@SniperJoe](https://github.com/SniperJoe)
27
+
28
+
29
+ ## @intlify/bundle-utils@2.1.0 (2021-11-10)
30
+
31
+ #### :zap: Improvement Features
32
+ * [#67](https://github.com/intlify/bundle-tools/pull/67) fix: add vite and vue-i18n as peerDependencies ([@AlexandreBonaventure](https://github.com/AlexandreBonaventure))
33
+
34
+ #### Committers: 1
35
+ - Alexandre Bonaventure Geissmann ([@AlexandreBonaventure](https://github.com/AlexandreBonaventure))
36
+
37
+
2
38
  ## @intlify/bundle-utils@2.0.0 (2021-10-24)
3
39
 
4
40
  #### :star: Features
package/lib/codegen.d.ts CHANGED
@@ -32,6 +32,7 @@ export interface CodeGenOptions {
32
32
  locale?: string;
33
33
  env?: DevEnv;
34
34
  forceStringify?: boolean;
35
+ useClassComponent?: boolean;
35
36
  onWarn?: (msg: string) => void;
36
37
  onError?: (msg: string) => void;
37
38
  }
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 } = (0, message_compiler_1.baseCompile)(msg, newOptions);
105
+ const { code, ast, map } = 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 }: CodeGenOptions, injector?: () => string): CodeGenResult<JSONProgram>;
10
+ export declare function generate(targetSource: string | Buffer, { type, bridge, 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 }, injector) {
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) {
14
14
  const target = Buffer.isBuffer(targetSource)
15
15
  ? targetSource.toString()
16
16
  : targetSource;
@@ -28,10 +28,11 @@ function generate(targetSource, { type = 'plain', bridge = false, filename = 'vu
28
28
  inSourceMap,
29
29
  env,
30
30
  filename,
31
- forceStringify
31
+ forceStringify,
32
+ useClassComponent
32
33
  };
33
- const generator = (0, codegen_1.createCodeGenerator)(options);
34
- const ast = (0, jsonc_eslint_parser_1.parseJSON)(value, { filePath: filename });
34
+ const generator = codegen_1.createCodeGenerator(options);
35
+ const ast = jsonc_eslint_parser_1.parseJSON(value, { filePath: filename });
35
36
  const codeMaps = generateNode(generator, ast, options, injector);
36
37
  const { code, map } = generator.context();
37
38
  // if (map) {
@@ -42,7 +43,7 @@ function generate(targetSource, { type = 'plain', bridge = false, filename = 'vu
42
43
  // }
43
44
  // prettier-ignore
44
45
  const newMap = map
45
- ? (0, codegen_1.mapLinesColumns)(map.toJSON(), codeMaps, inSourceMap) || null // eslint-disable-line @typescript-eslint/no-explicit-any
46
+ ? codegen_1.mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null // eslint-disable-line @typescript-eslint/no-explicit-any
46
47
  : null;
47
48
  return {
48
49
  ast,
@@ -56,9 +57,13 @@ function generateNode(generator, node, options, injector) {
56
57
  const itemsCountStack = [];
57
58
  const { forceStringify } = generator.context();
58
59
  const codeMaps = new Map();
59
- const { type, bridge, sourceMap, isGlobal, locale } = options;
60
- const componentNamespace = bridge ? `Component.options.` : `Component.`;
61
- (0, jsonc_eslint_parser_1.traverseNodes)(node, {
60
+ const { type, bridge, sourceMap, isGlobal, locale, useClassComponent } = options;
61
+ const componentNamespace = bridge
62
+ ? `Component.options`
63
+ : useClassComponent
64
+ ? `Component.__o`
65
+ : `Component`;
66
+ jsonc_eslint_parser_1.traverseNodes(node, {
62
67
  enterNode(node, parent) {
63
68
  switch (node.type) {
64
69
  case 'Program':
@@ -72,8 +77,8 @@ function generateNode(generator, node, options, injector) {
72
77
  const exportSyntax = bridge ? `module.exports =` : `export default`;
73
78
  generator.push(`${exportSyntax} function (Component) {`);
74
79
  generator.indent();
75
- generator.pushline(`${componentNamespace}${variableName} = ${componentNamespace}${variableName} || []`);
76
- generator.push(`${componentNamespace}${variableName}.push({`);
80
+ generator.pushline(`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`);
81
+ generator.push(`${componentNamespace}.${variableName}.push({`);
77
82
  generator.indent();
78
83
  generator.pushline(`"locale": ${JSON.stringify(localeName)},`);
79
84
  generator.push(`"resource": `);
@@ -94,9 +99,9 @@ function generateNode(generator, node, options, injector) {
94
99
  node.key.type === 'JSONIdentifier')) {
95
100
  const name = node.key.type === 'JSONLiteral' ? node.key.value : node.key.name;
96
101
  const value = node.value.value;
97
- if ((0, shared_1.isString)(value)) {
102
+ if (shared_1.isString(value)) {
98
103
  generator.push(`${JSON.stringify(name)}: `);
99
- const { code, map } = (0, codegen_1.generateMessageFunction)(value, options);
104
+ const { code, map } = codegen_1.generateMessageFunction(value, options);
100
105
  sourceMap && map != null && codeMaps.set(value, map);
101
106
  generator.push(`${code}`, node.value, value);
102
107
  }
@@ -104,7 +109,7 @@ function generateNode(generator, node, options, injector) {
104
109
  if (forceStringify) {
105
110
  const strValue = JSON.stringify(value);
106
111
  generator.push(`${JSON.stringify(name)}: `);
107
- const { code, map } = (0, codegen_1.generateMessageFunction)(strValue, options);
112
+ const { code, map } = codegen_1.generateMessageFunction(strValue, options);
108
113
  sourceMap && map != null && codeMaps.set(strValue, map);
109
114
  generator.push(`${code}`, node.value, strValue);
110
115
  }
@@ -132,15 +137,15 @@ function generateNode(generator, node, options, injector) {
132
137
  if (parent.type === 'JSONArrayExpression') {
133
138
  if (node.type === 'JSONLiteral') {
134
139
  const value = node.value;
135
- if ((0, shared_1.isString)(value)) {
136
- const { code, map } = (0, codegen_1.generateMessageFunction)(value, options);
140
+ if (shared_1.isString(value)) {
141
+ const { code, map } = codegen_1.generateMessageFunction(value, options);
137
142
  sourceMap && map != null && codeMaps.set(value, map);
138
143
  generator.push(`${code}`, node, value);
139
144
  }
140
145
  else {
141
146
  if (forceStringify) {
142
147
  const strValue = JSON.stringify(value);
143
- const { code, map } = (0, codegen_1.generateMessageFunction)(strValue, options);
148
+ const { code, map } = codegen_1.generateMessageFunction(strValue, options);
144
149
  sourceMap && map != null && codeMaps.set(strValue, map);
145
150
  generator.push(`${code}`, node, strValue);
146
151
  }
@@ -165,9 +170,9 @@ function generateNode(generator, node, options, injector) {
165
170
  generator.push(`})`);
166
171
  if (bridge && injector) {
167
172
  generator.newline();
168
- generator.pushline(`${componentNamespace}__i18nBridge = ${componentNamespace}__i18nBridge || []`);
169
- generator.pushline(`${componentNamespace}__i18nBridge.push('${injector()}')`);
170
- generator.pushline(`delete ${componentNamespace}_Ctor`);
173
+ generator.pushline(`${componentNamespace}.__i18nBridge = ${componentNamespace}.__i18nBridge || []`);
174
+ generator.pushline(`${componentNamespace}.__i18nBridge.push('${injector()}')`);
175
+ generator.pushline(`delete ${componentNamespace}._Ctor`);
171
176
  }
172
177
  generator.deindent();
173
178
  generator.pushline(`}`);
@@ -196,12 +201,20 @@ function generateNode(generator, node, options, injector) {
196
201
  }
197
202
  generator.deindent();
198
203
  generator.push(`]`);
204
+ if (parent.type === 'JSONArrayExpression') {
205
+ if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
206
+ generator.pushline(`,`);
207
+ }
208
+ }
199
209
  break;
200
210
  case 'JSONLiteral':
201
211
  if (parent.type === 'JSONArrayExpression') {
202
212
  if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
203
213
  generator.pushline(`,`);
204
214
  }
215
+ else {
216
+ generator.pushline(`,`);
217
+ }
205
218
  }
206
219
  break;
207
220
  default:
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, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify }: CodeGenOptions, injector?: () => string): CodeGenResult<YAMLProgram>;
10
+ export declare function generate(targetSource: string | Buffer, { type, bridge, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify }: CodeGenOptions, injector?: () => string): CodeGenResult<YAMLProgram>;
package/lib/yaml.js CHANGED
@@ -10,7 +10,7 @@ const yaml_eslint_parser_1 = require("yaml-eslint-parser");
10
10
  /**
11
11
  * @internal
12
12
  */
13
- function generate(targetSource, { type = 'plain', bridge = 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, 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;
@@ -24,15 +24,16 @@ function generate(targetSource, { type = 'plain', bridge = false, filename = 'vu
24
24
  inSourceMap,
25
25
  env,
26
26
  filename,
27
- forceStringify
27
+ forceStringify,
28
+ useClassComponent
28
29
  };
29
- const generator = (0, codegen_1.createCodeGenerator)(options);
30
- const ast = (0, yaml_eslint_parser_1.parseYAML)(value, { filePath: filename });
30
+ const generator = codegen_1.createCodeGenerator(options);
31
+ const ast = yaml_eslint_parser_1.parseYAML(value, { filePath: filename });
31
32
  const codeMaps = generateNode(generator, ast, options, injector);
32
33
  const { code, map } = generator.context();
33
34
  // prettier-ignore
34
35
  const newMap = map
35
- ? (0, codegen_1.mapLinesColumns)(map.toJSON(), codeMaps, inSourceMap) || null // eslint-disable-line @typescript-eslint/no-explicit-any
36
+ ? codegen_1.mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null // eslint-disable-line @typescript-eslint/no-explicit-any
36
37
  : null;
37
38
  return {
38
39
  ast,
@@ -46,9 +47,13 @@ function generateNode(generator, node, options, injector) {
46
47
  const itemsCountStack = [];
47
48
  const { forceStringify } = generator.context();
48
49
  const codeMaps = new Map();
49
- const { type, bridge, sourceMap, isGlobal, locale } = options;
50
- const componentNamespace = bridge ? `Component.options.` : `Component.`;
51
- (0, yaml_eslint_parser_1.traverseNodes)(node, {
50
+ const { type, bridge, sourceMap, isGlobal, locale, useClassComponent } = options;
51
+ const componentNamespace = bridge
52
+ ? `Component.options`
53
+ : useClassComponent
54
+ ? `Component.__o`
55
+ : `Component`;
56
+ yaml_eslint_parser_1.traverseNodes(node, {
52
57
  enterNode(node, parent) {
53
58
  switch (node.type) {
54
59
  case 'Program':
@@ -61,8 +66,8 @@ function generateNode(generator, node, options, injector) {
61
66
  const exportSyntax = bridge ? `module.exports =` : `export default`;
62
67
  generator.push(`${exportSyntax} function (Component) {`);
63
68
  generator.indent();
64
- generator.pushline(`${componentNamespace}${variableName} = ${componentNamespace}${variableName} || []`);
65
- generator.push(`${componentNamespace}${variableName}.push({`);
69
+ generator.pushline(`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`);
70
+ generator.push(`${componentNamespace}.${variableName}.push({`);
66
71
  generator.indent();
67
72
  generator.pushline(`"locale": ${JSON.stringify(localeName)},`);
68
73
  generator.push(`"resource": `);
@@ -84,9 +89,9 @@ function generateNode(generator, node, options, injector) {
84
89
  node.key.type === 'YAMLScalar') {
85
90
  const name = node.key.value;
86
91
  const value = node.value.value;
87
- if ((0, shared_1.isString)(value)) {
92
+ if (shared_1.isString(value)) {
88
93
  generator.push(`${JSON.stringify(name)}: `);
89
- const { code, map } = (0, codegen_1.generateMessageFunction)(value, options);
94
+ const { code, map } = codegen_1.generateMessageFunction(value, options);
90
95
  sourceMap && map != null && codeMaps.set(value, map);
91
96
  generator.push(`${code}`, node.value, value);
92
97
  }
@@ -94,7 +99,7 @@ function generateNode(generator, node, options, injector) {
94
99
  if (forceStringify) {
95
100
  const strValue = JSON.stringify(value);
96
101
  generator.push(`${JSON.stringify(name)}: `);
97
- const { code, map } = (0, codegen_1.generateMessageFunction)(strValue, options);
102
+ const { code, map } = codegen_1.generateMessageFunction(strValue, options);
98
103
  sourceMap && map != null && codeMaps.set(strValue, map);
99
104
  generator.push(`${code}`, node.value, strValue);
100
105
  }
@@ -123,15 +128,15 @@ function generateNode(generator, node, options, injector) {
123
128
  if (parent.type === 'YAMLSequence') {
124
129
  if (node.type === 'YAMLScalar') {
125
130
  const value = node.value;
126
- if ((0, shared_1.isString)(value)) {
127
- const { code, map } = (0, codegen_1.generateMessageFunction)(value, options);
131
+ if (shared_1.isString(value)) {
132
+ const { code, map } = codegen_1.generateMessageFunction(value, options);
128
133
  sourceMap && map != null && codeMaps.set(value, map);
129
134
  generator.push(`${code}`, node, value);
130
135
  }
131
136
  else {
132
137
  if (forceStringify) {
133
138
  const strValue = JSON.stringify(value);
134
- const { code, map } = (0, codegen_1.generateMessageFunction)(strValue, options);
139
+ const { code, map } = codegen_1.generateMessageFunction(strValue, options);
135
140
  sourceMap && map != null && codeMaps.set(strValue, map);
136
141
  generator.push(`${code}`, node, strValue);
137
142
  }
@@ -156,9 +161,9 @@ function generateNode(generator, node, options, injector) {
156
161
  generator.push(`})`);
157
162
  if (bridge && injector) {
158
163
  generator.newline();
159
- generator.pushline(`${componentNamespace}__i18nBridge = ${componentNamespace}__i18nBridge || []`);
160
- generator.pushline(`${componentNamespace}__i18nBridge.push('${injector()}')`);
161
- generator.pushline(`delete ${componentNamespace}_Ctor`);
164
+ generator.pushline(`${componentNamespace}.__i18nBridge = ${componentNamespace}.__i18nBridge || []`);
165
+ generator.pushline(`${componentNamespace}.__i18nBridge.push('${injector()}')`);
166
+ generator.pushline(`delete ${componentNamespace}._Ctor`);
162
167
  }
163
168
  generator.deindent();
164
169
  generator.push(`}`);
@@ -187,12 +192,20 @@ function generateNode(generator, node, options, injector) {
187
192
  }
188
193
  generator.deindent();
189
194
  generator.push(`]`);
195
+ if (parent.type === 'YAMLSequence') {
196
+ if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
197
+ generator.pushline(`,`);
198
+ }
199
+ }
190
200
  break;
191
201
  case 'YAMLScalar':
192
202
  if (parent.type === 'YAMLSequence') {
193
203
  if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
194
204
  generator.pushline(`,`);
195
205
  }
206
+ else {
207
+ generator.pushline(`,`);
208
+ }
196
209
  }
197
210
  break;
198
211
  default:
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.0.0",
4
+ "version": "2.2.1",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -9,6 +9,15 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/intlify/bundle-tools/issues"
11
11
  },
12
+ "peerDependencies": {},
13
+ "peerDependenciesMeta": {
14
+ "vue-i18n": {
15
+ "optional": true
16
+ },
17
+ "petite-vue-i18n": {
18
+ "optional": true
19
+ }
20
+ },
12
21
  "dependencies": {
13
22
  "@intlify/message-compiler": "beta",
14
23
  "@intlify/shared": "beta",
@@ -26,7 +35,6 @@
26
35
  "homepage": "https://github.com/intlify/bundle-tools/blob/main/packages/bundle-utils/README.md",
27
36
  "license": "MIT",
28
37
  "main": "lib/index.js",
29
- "peerDependencies": {},
30
38
  "repository": {
31
39
  "type": "git",
32
40
  "url": "git+https://github.com/intlify/bundle-tools.git",