@vocab/webpack 1.2.0 → 1.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.
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var path = require('path');
6
+ var cjsModuleLexer = require('cjs-module-lexer');
6
7
  var esModuleLexer = require('es-module-lexer');
7
8
  var core = require('@vocab/core');
8
9
  var chunkName_dist_vocabWebpackChunkName = require('../../chunk-name/dist/vocab-webpack-chunk-name.cjs.dev.js');
@@ -12,7 +13,27 @@ require('debug');
12
13
 
13
14
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
14
15
 
16
+ function _interopNamespace(e) {
17
+ if (e && e.__esModule) return e;
18
+ var n = Object.create(null);
19
+ if (e) {
20
+ Object.keys(e).forEach(function (k) {
21
+ if (k !== 'default') {
22
+ var d = Object.getOwnPropertyDescriptor(e, k);
23
+ Object.defineProperty(n, k, d.get ? d : {
24
+ enumerable: true,
25
+ get: function () { return e[k]; }
26
+ });
27
+ }
28
+ });
29
+ }
30
+ n["default"] = e;
31
+ return Object.freeze(n);
32
+ }
33
+
15
34
  var path__default = /*#__PURE__*/_interopDefault(path);
35
+ var cjsModuleLexer__namespace = /*#__PURE__*/_interopNamespace(cjsModuleLexer);
36
+ var esModuleLexer__namespace = /*#__PURE__*/_interopNamespace(esModuleLexer);
16
37
 
17
38
  const trace = logger.trace.extend('loader');
18
39
 
@@ -52,8 +73,14 @@ function renderLanguageLoaderAsync(resourcePath, loadedTranslation) {
52
73
  );
53
74
  };
54
75
  }
55
- function findExportNames(source) {
56
- const [, exports] = esModuleLexer.parse(source);
76
+ function findExportNames(source, mode) {
77
+ if (mode === 'esm') {
78
+ const [, exports] = esModuleLexer__namespace.parse(source);
79
+ return exports;
80
+ }
81
+ const {
82
+ exports
83
+ } = cjsModuleLexer__namespace.parse(source);
57
84
  return exports;
58
85
  }
59
86
  async function vocabLoader(source) {
@@ -62,7 +89,6 @@ async function vocabLoader(source) {
62
89
  if (!callback) {
63
90
  throw new Error(`Webpack didn't provide an async callback`);
64
91
  }
65
- await esModuleLexer.init;
66
92
  const config = this.getOptions();
67
93
  const devJsonFilePath = core.getDevLanguageFileFromTsFile(this.resourcePath);
68
94
  const loadedTranslation = core.loadTranslation({
@@ -76,16 +102,35 @@ async function vocabLoader(source) {
76
102
  return;
77
103
  }
78
104
  const renderLanguageLoader = renderLanguageLoaderAsync.call(this, devJsonFilePath, loadedTranslation);
79
- const loadedLanguages = Object.keys(loadedTranslation.languages);
80
- const exportName = findExportNames(source)[0];
81
- const result = /* ts */`
82
- import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
83
-
105
+ const translations = /* ts */`
84
106
  const translations = createTranslationFile({
85
- ${loadedLanguages.map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
86
- });
87
- export { translations as ${exportName} };
107
+ ${Object.keys(loadedTranslation.languages).map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
108
+ });
88
109
  `;
110
+ let result;
111
+
112
+ // this is necessary for the Web Assembly boot
113
+ await esModuleLexer__namespace.init;
114
+ const esmExports = findExportNames(source, 'esm');
115
+ if (esmExports.length > 0) {
116
+ const exportName = esmExports[0];
117
+ trace(`Found ESM export '${exportName}' in ${this.resourcePath}`);
118
+ result = /* ts */`
119
+ import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
120
+ ${translations}
121
+ export { translations as ${exportName} };
122
+ `;
123
+ } else {
124
+ // init needs to be called and waited upon
125
+ await cjsModuleLexer__namespace.init();
126
+ const exportName = findExportNames(source, 'cjs')[0];
127
+ trace(`Found CJS export '${exportName}' in ${this.resourcePath}`);
128
+ result = /* ts */`
129
+ const { createLanguage, createTranslationFile } = require('@vocab/webpack/${target}');
130
+ ${translations}
131
+ exports.${exportName} = translations;
132
+ `;
133
+ }
89
134
  trace('Created translation file', result);
90
135
  callback(null, result);
91
136
  }
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var path = require('path');
6
+ var cjsModuleLexer = require('cjs-module-lexer');
6
7
  var esModuleLexer = require('es-module-lexer');
7
8
  var core = require('@vocab/core');
8
9
  var chunkName_dist_vocabWebpackChunkName = require('../../chunk-name/dist/vocab-webpack-chunk-name.cjs.prod.js');
@@ -12,7 +13,27 @@ require('debug');
12
13
 
13
14
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
14
15
 
16
+ function _interopNamespace(e) {
17
+ if (e && e.__esModule) return e;
18
+ var n = Object.create(null);
19
+ if (e) {
20
+ Object.keys(e).forEach(function (k) {
21
+ if (k !== 'default') {
22
+ var d = Object.getOwnPropertyDescriptor(e, k);
23
+ Object.defineProperty(n, k, d.get ? d : {
24
+ enumerable: true,
25
+ get: function () { return e[k]; }
26
+ });
27
+ }
28
+ });
29
+ }
30
+ n["default"] = e;
31
+ return Object.freeze(n);
32
+ }
33
+
15
34
  var path__default = /*#__PURE__*/_interopDefault(path);
35
+ var cjsModuleLexer__namespace = /*#__PURE__*/_interopNamespace(cjsModuleLexer);
36
+ var esModuleLexer__namespace = /*#__PURE__*/_interopNamespace(esModuleLexer);
16
37
 
17
38
  const trace = logger.trace.extend('loader');
18
39
 
@@ -52,8 +73,14 @@ function renderLanguageLoaderAsync(resourcePath, loadedTranslation) {
52
73
  );
53
74
  };
54
75
  }
55
- function findExportNames(source) {
56
- const [, exports] = esModuleLexer.parse(source);
76
+ function findExportNames(source, mode) {
77
+ if (mode === 'esm') {
78
+ const [, exports] = esModuleLexer__namespace.parse(source);
79
+ return exports;
80
+ }
81
+ const {
82
+ exports
83
+ } = cjsModuleLexer__namespace.parse(source);
57
84
  return exports;
58
85
  }
59
86
  async function vocabLoader(source) {
@@ -62,7 +89,6 @@ async function vocabLoader(source) {
62
89
  if (!callback) {
63
90
  throw new Error(`Webpack didn't provide an async callback`);
64
91
  }
65
- await esModuleLexer.init;
66
92
  const config = this.getOptions();
67
93
  const devJsonFilePath = core.getDevLanguageFileFromTsFile(this.resourcePath);
68
94
  const loadedTranslation = core.loadTranslation({
@@ -76,16 +102,35 @@ async function vocabLoader(source) {
76
102
  return;
77
103
  }
78
104
  const renderLanguageLoader = renderLanguageLoaderAsync.call(this, devJsonFilePath, loadedTranslation);
79
- const loadedLanguages = Object.keys(loadedTranslation.languages);
80
- const exportName = findExportNames(source)[0];
81
- const result = /* ts */`
82
- import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
83
-
105
+ const translations = /* ts */`
84
106
  const translations = createTranslationFile({
85
- ${loadedLanguages.map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
86
- });
87
- export { translations as ${exportName} };
107
+ ${Object.keys(loadedTranslation.languages).map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
108
+ });
88
109
  `;
110
+ let result;
111
+
112
+ // this is necessary for the Web Assembly boot
113
+ await esModuleLexer__namespace.init;
114
+ const esmExports = findExportNames(source, 'esm');
115
+ if (esmExports.length > 0) {
116
+ const exportName = esmExports[0];
117
+ trace(`Found ESM export '${exportName}' in ${this.resourcePath}`);
118
+ result = /* ts */`
119
+ import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
120
+ ${translations}
121
+ export { translations as ${exportName} };
122
+ `;
123
+ } else {
124
+ // init needs to be called and waited upon
125
+ await cjsModuleLexer__namespace.init();
126
+ const exportName = findExportNames(source, 'cjs')[0];
127
+ trace(`Found CJS export '${exportName}' in ${this.resourcePath}`);
128
+ result = /* ts */`
129
+ const { createLanguage, createTranslationFile } = require('@vocab/webpack/${target}');
130
+ ${translations}
131
+ exports.${exportName} = translations;
132
+ `;
133
+ }
89
134
  trace('Created translation file', result);
90
135
  callback(null, result);
91
136
  }
@@ -1,5 +1,6 @@
1
1
  import path from 'path';
2
- import { init, parse } from 'es-module-lexer';
2
+ import * as cjsModuleLexer from 'cjs-module-lexer';
3
+ import * as esModuleLexer from 'es-module-lexer';
3
4
  import { getDevLanguageFileFromTsFile, loadTranslation } from '@vocab/core';
4
5
  import { getChunkName } from '../../chunk-name/dist/vocab-webpack-chunk-name.esm.js';
5
6
  import { t as trace$1 } from '../../dist/logger-e1862ea1.esm.js';
@@ -44,8 +45,14 @@ function renderLanguageLoaderAsync(resourcePath, loadedTranslation) {
44
45
  );
45
46
  };
46
47
  }
47
- function findExportNames(source) {
48
- const [, exports] = parse(source);
48
+ function findExportNames(source, mode) {
49
+ if (mode === 'esm') {
50
+ const [, exports] = esModuleLexer.parse(source);
51
+ return exports;
52
+ }
53
+ const {
54
+ exports
55
+ } = cjsModuleLexer.parse(source);
49
56
  return exports;
50
57
  }
51
58
  async function vocabLoader(source) {
@@ -54,7 +61,6 @@ async function vocabLoader(source) {
54
61
  if (!callback) {
55
62
  throw new Error(`Webpack didn't provide an async callback`);
56
63
  }
57
- await init;
58
64
  const config = this.getOptions();
59
65
  const devJsonFilePath = getDevLanguageFileFromTsFile(this.resourcePath);
60
66
  const loadedTranslation = loadTranslation({
@@ -68,16 +74,35 @@ async function vocabLoader(source) {
68
74
  return;
69
75
  }
70
76
  const renderLanguageLoader = renderLanguageLoaderAsync.call(this, devJsonFilePath, loadedTranslation);
71
- const loadedLanguages = Object.keys(loadedTranslation.languages);
72
- const exportName = findExportNames(source)[0];
73
- const result = /* ts */`
74
- import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
75
-
77
+ const translations = /* ts */`
76
78
  const translations = createTranslationFile({
77
- ${loadedLanguages.map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
78
- });
79
- export { translations as ${exportName} };
79
+ ${Object.keys(loadedTranslation.languages).map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
80
+ });
80
81
  `;
82
+ let result;
83
+
84
+ // this is necessary for the Web Assembly boot
85
+ await esModuleLexer.init;
86
+ const esmExports = findExportNames(source, 'esm');
87
+ if (esmExports.length > 0) {
88
+ const exportName = esmExports[0];
89
+ trace(`Found ESM export '${exportName}' in ${this.resourcePath}`);
90
+ result = /* ts */`
91
+ import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
92
+ ${translations}
93
+ export { translations as ${exportName} };
94
+ `;
95
+ } else {
96
+ // init needs to be called and waited upon
97
+ await cjsModuleLexer.init();
98
+ const exportName = findExportNames(source, 'cjs')[0];
99
+ trace(`Found CJS export '${exportName}' in ${this.resourcePath}`);
100
+ result = /* ts */`
101
+ const { createLanguage, createTranslationFile } = require('@vocab/webpack/${target}');
102
+ ${translations}
103
+ exports.${exportName} = translations;
104
+ `;
105
+ }
81
106
  trace('Created translation file', result);
82
107
  callback(null, result);
83
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocab/webpack",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/vocab-webpack.cjs.js",
5
5
  "module": "dist/vocab-webpack.esm.js",
6
6
  "exports": {
@@ -41,6 +41,7 @@
41
41
  "dependencies": {
42
42
  "@vocab/core": "^1.3.0",
43
43
  "chalk": "^4.1.0",
44
+ "cjs-module-lexer": "^1.2.2",
44
45
  "debug": "^4.3.1",
45
46
  "es-module-lexer": "^0.9.3",
46
47
  "virtual-resource-loader": "^1.0.1"