@e-mc/document 0.5.3 → 0.6.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/asset.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { ExternalAsset } from '../types/lib/asset';
1
+ import type { ExternalAsset, InitialValue } from '../types/lib/asset';
2
2
 
3
3
  declare namespace asset {
4
4
  function isEqual(item: ExternalAsset, other: ExternalAsset): boolean;
5
- function setInitialValue(file: ExternalAsset, cacheable?: boolean): void;
5
+ function setInitialValue(file: ExternalAsset, cacheable?: boolean): InitialValue;
6
6
  }
7
7
 
8
8
  export = asset;
package/asset.js CHANGED
@@ -6,6 +6,6 @@ function isEqual(item, other) {
6
6
  }
7
7
  exports.isEqual = isEqual;
8
8
  function setInitialValue(file, cacheable = true) {
9
- file.initialValue || (file.initialValue = { pathname: file.pathname, filename: file.filename, mimeType: file.mimeType, localUri: file.localUri, inlineFilename: file.inlineFilename, cacheable });
9
+ return file.initialValue || (file.initialValue = { pathname: file.pathname, filename: file.filename, mimeType: file.mimeType, localUri: file.localUri, inlineFilename: file.inlineFilename, cacheable });
10
10
  }
11
11
  exports.setInitialValue = setInitialValue;
package/index.js CHANGED
@@ -11,24 +11,6 @@ const db_1 = require("../db");
11
11
  const util_1 = require("./util");
12
12
  const transform_1 = require("./transform");
13
13
  const parse_1 = require("./parse");
14
- const PIR_PLUGINS = Object.freeze({
15
- "@babel/core": "@pi-r/babel",
16
- "clean-css": "@pi-r/clean-css",
17
- "csso": "@pi-r/csso",
18
- "eslint": "@pi-r/eslint",
19
- "html-minifier": "@pi-r/html-minifier",
20
- "html-minifier-terser": "@pi-r/html-minifier-terser",
21
- "html-validate": "@pi-r/html-validate",
22
- "postcss": "@pi-r/postcss",
23
- "posthtml": "@pi-r/posthtml",
24
- "prettier": "@pi-r/prettier",
25
- "rollup": "@pi-r/rollup",
26
- "sass": "@pi-r/sass",
27
- "stylelint": "@pi-r/stylelint",
28
- "svgo": "@pi-r/svgo",
29
- "terser": "@pi-r/terser",
30
- "uglify-js": "@pi-r/uglify-js"
31
- });
32
14
  const CACHE_PACKAGE = {};
33
15
  const CACHE_REQUIRE = {};
34
16
  const CACHE_ETAG = {};
@@ -334,6 +316,7 @@ class Document extends core_1.Client {
334
316
  this._dataSource = null;
335
317
  this._transformConfig = null;
336
318
  this._mimeMap = null;
319
+ this._imports = null;
337
320
  const transform = this.settingsOf('transform', 'cache');
338
321
  if (transform !== undefined) {
339
322
  this.customize({ transform });
@@ -365,7 +348,10 @@ class Document extends core_1.Client {
365
348
  }
366
349
  if ((0, types_1.isPlainObject)(pages)) {
367
350
  let mimeMap;
368
- if (!(0, types_1.isPlainObject)(mimeMap = pages[baseUrl])) {
351
+ if ((0, types_1.isPlainObject)(mimeMap = pages[baseUrl])) {
352
+ mimeMap = { ...mimeMap };
353
+ }
354
+ else {
369
355
  const items = [];
370
356
  for (const pattern in pages) {
371
357
  const item = pages[pattern];
@@ -390,8 +376,8 @@ class Document extends core_1.Client {
390
376
  items.sort((a, b) => typeof a.ordinal === 'number' && typeof b.ordinal === 'number' ? a.ordinal - b.ordinal : 0);
391
377
  mimeMap = items.reduce((a, b) => Object.assign(a, b), {});
392
378
  }
393
- else {
394
- mimeMap = items[0];
379
+ else if (items.length) {
380
+ mimeMap = { ...items[0] };
395
381
  }
396
382
  }
397
383
  if (mimeMap) {
@@ -417,6 +403,7 @@ class Document extends core_1.Client {
417
403
  try {
418
404
  const Handler = require(handler);
419
405
  if (isFunction(Handler) && Handler.prototype instanceof core_1.ClientDb) {
406
+ // @ts-ignore
420
407
  instance = new Handler(db, database);
421
408
  }
422
409
  else {
@@ -874,7 +861,7 @@ class Document extends core_1.Client {
874
861
  }
875
862
  for (let i = 0, j = 0, row; i < length; ++i) {
876
863
  if ((0, types_1.isPlainObject)(row = data[i])) {
877
- row['__index__'] ?? (row['__index__'] = ++j);
864
+ row.__index__ ?? (row.__index__ = ++j);
878
865
  if (output) {
879
866
  row = { ...output, ...row };
880
867
  }
@@ -900,10 +887,8 @@ class Document extends core_1.Client {
900
887
  return null;
901
888
  }
902
889
  async transform(type, code, format, options = {}) {
903
- var _a;
904
- let transform = this.settings.transform;
905
- const data = transform?.[type];
906
- if (!(0, types_1.isObject)(data)) {
890
+ let transform = this.settings.transform, data;
891
+ if (!transform || !(0, types_1.isObject)(data = transform[type])) {
907
892
  return;
908
893
  }
909
894
  format = typeof format === 'string' ? format.trim().split(/\s*\+\s*/) : format.map(item => typeof item === 'string' ? item.trim() : '');
@@ -994,7 +979,7 @@ class Document extends core_1.Client {
994
979
  if (cacheData) {
995
980
  delete options.cacheData;
996
981
  }
997
- const imports = (_a = transform).imports || (_a.imports = {});
982
+ const imports = transform.imports || (transform.imports = {});
998
983
  const series = new transform_1.TransformSeries(type, code, options);
999
984
  series.init(this, __dirname);
1000
985
  let valid, excluded, userData, userImports, ignoreCache, storedLog, sourceFiles;
@@ -1132,7 +1117,7 @@ class Document extends core_1.Client {
1132
1117
  let transformer = CACHE_PACKAGE[plugin + username];
1133
1118
  if (!transformer) {
1134
1119
  try {
1135
- let pkg = this.resolveDir('package', plugin + '.js') || userImports?.[plugin] || imports[plugin] || PIR_PLUGINS[plugin];
1120
+ let pkg = this.resolveDir('package', plugin + '.js') || userImports?.[plugin] || imports[plugin] || util_1.IMPORTS[plugin];
1136
1121
  if ((0, types_1.isString)(pkg)) {
1137
1122
  const match = /^(@?\S+)@(\d+(?:\.\d+(?:\.\S+)?)?|[a-z]+)$/.exec(pkg);
1138
1123
  if (match) {
@@ -1143,10 +1128,13 @@ class Document extends core_1.Client {
1143
1128
  }
1144
1129
  else {
1145
1130
  transformer = context;
1146
- context = this;
1131
+ context = this; // eslint-disable-line @typescript-eslint/no-this-alias
1147
1132
  pkg = undefined;
1148
1133
  }
1149
- if (typeof transformer !== 'function' && typeof (transformer = transformer?.['default']) !== 'function') {
1134
+ if (transformer && typeof transformer !== 'function') {
1135
+ transformer = transformer.default;
1136
+ }
1137
+ if (typeof transformer !== 'function') {
1150
1138
  throw (0, types_1.errorMessage)(plugin, pkg || name, 'Invalid function');
1151
1139
  }
1152
1140
  if (pkg) {
@@ -1287,6 +1275,27 @@ class Document extends core_1.Client {
1287
1275
  }
1288
1276
  return this._dataSource || [];
1289
1277
  }
1278
+ set imports(value) {
1279
+ if (!(0, types_1.isPlainObject)(value)) {
1280
+ this._imports = null;
1281
+ return;
1282
+ }
1283
+ let imports = this._imports;
1284
+ if (imports) {
1285
+ this._imports = Object.assign(imports, value);
1286
+ }
1287
+ else {
1288
+ const username = this.host?.username;
1289
+ imports = username && this.settings.users?.[username]?.imports || this.module.imports;
1290
+ this._imports = Object.assign(this._imports || {}, (0, types_1.isPlainObject)(imports) ? imports : undefined, value);
1291
+ }
1292
+ }
1293
+ get imports() {
1294
+ if (!this._imports) {
1295
+ this.imports = {};
1296
+ }
1297
+ return this._imports;
1298
+ }
1290
1299
  get watching() {
1291
1300
  return this.assets.some(item => item.watch);
1292
1301
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,9 +20,9 @@
20
20
  "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.5.3",
24
- "@e-mc/db": "0.5.3",
25
- "@e-mc/types": "0.5.3",
23
+ "@e-mc/core": "0.6.0",
24
+ "@e-mc/db": "0.6.0",
25
+ "@e-mc/types": "0.6.0",
26
26
  "chalk": "4.1.2",
27
27
  "htmlparser2": "^9.0.0",
28
28
  "js-yaml": "^4.1.0",
package/parse/index.js CHANGED
@@ -11,7 +11,7 @@ var IGNORE_FLAG;
11
11
  IGNORE_FLAG[IGNORE_FLAG["NONE"] = 0] = "NONE";
12
12
  IGNORE_FLAG[IGNORE_FLAG["INTERIOR"] = 1] = "INTERIOR";
13
13
  IGNORE_FLAG[IGNORE_FLAG["LOCATOR"] = 2] = "LOCATOR";
14
- })(IGNORE_FLAG = exports.IGNORE_FLAG || (exports.IGNORE_FLAG = {}));
14
+ })(IGNORE_FLAG || (exports.IGNORE_FLAG = IGNORE_FLAG = {}));
15
15
  const Parser = htmlparser2.Parser;
16
16
  const DomHandler = domhandler.DomHandler;
17
17
  const CACHE_TAGNAME = {};
@@ -186,20 +186,20 @@ class TransformSeries extends core_1.Module {
186
186
  }
187
187
  set version(value) {
188
188
  // @ts-ignore
189
- this.metadata['__version__'] = value;
189
+ this.metadata.__version__ = value;
190
190
  }
191
191
  get version() {
192
192
  // @ts-ignore
193
- return this.metadata['__version__'] || '';
193
+ return this.metadata.__version__ || '';
194
194
  }
195
195
  set packageName(value) {
196
196
  // @ts-ignore
197
- this.metadata['__packagename__'] = value;
197
+ this.metadata.__packagename__ = value;
198
198
  this.version = 'latest';
199
199
  }
200
200
  get packageName() {
201
201
  // @ts-ignore
202
- return this.metadata['__packagename__'] || '';
202
+ return this.metadata.__packagename__ || '';
203
203
  }
204
204
  get packageVersion() {
205
205
  const packageName = this.packageName;
@@ -316,6 +316,6 @@ class SourceMap {
316
316
  return this[kMap];
317
317
  }
318
318
  }
319
+ exports.SourceMap = SourceMap;
319
320
  _d = kMap;
320
321
  SourceMap.RE_SOURCE_MAPPING_URL = /(?:\r\n|\n)*(?:(\/\/)|(\/\*))\s*[#@][ ]+sourceMappingURL=(data:[^,]+,)?(\S+)\s*(\*\/)?\r?\n?/g;
321
- exports.SourceMap = SourceMap;
package/util.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  declare namespace util {
2
+ const IMPORTS: Record<string, string | undefined>;
2
3
  function loadPlugins<T = unknown>(name: string | unknown[], plugins?: unknown[]): T[];
3
4
  function replaceAll(source: string, valueOf: (name: string) => string, opening?: string, closing?: string): string;
4
5
  function concatString(values: string[] | string | undefined, newline?: string): string;
package/util.js CHANGED
@@ -1,9 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isObject = exports.removeInternalProperties = exports.getModuleName = exports.hasValue = exports.getHashData = exports.getNewline = exports.getIndent = exports.appendSuffix = exports.splitEnclosing = exports.concatString = exports.replaceAll = exports.loadPlugins = void 0;
3
+ exports.isObject = exports.removeInternalProperties = exports.getModuleName = exports.hasValue = exports.getHashData = exports.getNewline = exports.getIndent = exports.appendSuffix = exports.splitEnclosing = exports.concatString = exports.replaceAll = exports.loadPlugins = exports.IMPORTS = void 0;
4
4
  const path = require("path");
5
5
  const types_1 = require("../types");
6
6
  Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return types_1.isObject; } });
7
+ exports.IMPORTS = {
8
+ "@babel/core": "@pi-r/babel",
9
+ "clean-css": "@pi-r/clean-css",
10
+ "csso": "@pi-r/csso",
11
+ "eslint": "@pi-r/eslint",
12
+ "html-minifier": "@pi-r/html-minifier",
13
+ "html-minifier-terser": "@pi-r/html-minifier-terser",
14
+ "html-validate": "@pi-r/html-validate",
15
+ "postcss": "@pi-r/postcss",
16
+ "posthtml": "@pi-r/posthtml",
17
+ "prettier": "@pi-r/prettier",
18
+ "rollup": "@pi-r/rollup",
19
+ "sass": "@pi-r/sass",
20
+ "stylelint": "@pi-r/stylelint",
21
+ "svgo": "@pi-r/svgo",
22
+ "terser": "@pi-r/terser",
23
+ "uglify-js": "@pi-r/uglify-js"
24
+ };
7
25
  function loadPlugins(name, plugins = []) {
8
26
  if (Array.isArray(name)) {
9
27
  plugins = name;