@e-mc/document 0.5.3 → 0.7.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 });
@@ -342,30 +325,30 @@ class Document extends core_1.Client {
342
325
  restart() { }
343
326
  init(assets, config) {
344
327
  var _a;
345
- let ignoreModules;
328
+ let ignoreModules, ignoreExtensions;
346
329
  if (config) {
347
- const { baseUrl, ignoreExtensions } = config;
348
- if (ignoreExtensions === true) {
349
- this._extensions = [];
350
- }
351
- else if (typeof ignoreExtensions === 'string') {
352
- this._extensions = ignoreExtensions === this.moduleName ? [] : this._extensions.filter(value => value !== ignoreExtensions);
353
- }
354
- else if (Array.isArray(ignoreExtensions)) {
355
- this._extensions = ignoreExtensions.includes(this.moduleName) ? [] : this._extensions.filter(value => !ignoreExtensions.includes(value));
330
+ let baseUrl;
331
+ ({ baseUrl, ignoreModules, ignoreExtensions } = config);
332
+ let username, users;
333
+ if (username = this.host?.username) {
334
+ if (!(0, types_1.isPlainObject)(users = this.settings.users?.[username])) {
335
+ users = undefined;
336
+ }
337
+ else if (Array.isArray(users.extensions)) {
338
+ this._extensions = users.extensions.slice(0);
339
+ }
356
340
  }
357
341
  if (baseUrl) {
358
- const username = this.host?.username;
359
342
  let pages = this.settings.pages;
360
- if (username) {
361
- const users = this.settings.users?.[username]?.pages;
362
- if ((0, types_1.isPlainObject)(users)) {
363
- pages = (0, types_1.isPlainObject)(pages) ? { ...pages, ...users } : users;
364
- }
343
+ if (users && (0, types_1.isPlainObject)(users.pages)) {
344
+ pages = (0, types_1.isPlainObject)(pages) ? { ...pages, ...users.pages } : users.pages;
365
345
  }
366
346
  if ((0, types_1.isPlainObject)(pages)) {
367
347
  let mimeMap;
368
- if (!(0, types_1.isPlainObject)(mimeMap = pages[baseUrl])) {
348
+ if ((0, types_1.isPlainObject)(mimeMap = pages[baseUrl])) {
349
+ mimeMap = { ...mimeMap };
350
+ }
351
+ else {
369
352
  const items = [];
370
353
  for (const pattern in pages) {
371
354
  const item = pages[pattern];
@@ -390,8 +373,8 @@ class Document extends core_1.Client {
390
373
  items.sort((a, b) => typeof a.ordinal === 'number' && typeof b.ordinal === 'number' ? a.ordinal - b.ordinal : 0);
391
374
  mimeMap = items.reduce((a, b) => Object.assign(a, b), {});
392
375
  }
393
- else {
394
- mimeMap = items[0];
376
+ else if (items.length) {
377
+ mimeMap = { ...items[0] };
395
378
  }
396
379
  }
397
380
  if (mimeMap) {
@@ -406,7 +389,6 @@ class Document extends core_1.Client {
406
389
  }
407
390
  }
408
391
  }
409
- ignoreModules = config.ignoreModules;
410
392
  }
411
393
  if (this.dataSource.length && !ignoreModules?.includes('db')) {
412
394
  const db = (_a = this.module).db || (_a.db = {});
@@ -417,6 +399,7 @@ class Document extends core_1.Client {
417
399
  try {
418
400
  const Handler = require(handler);
419
401
  if (isFunction(Handler) && Handler.prototype instanceof core_1.ClientDb) {
402
+ // @ts-ignore
420
403
  instance = new Handler(db, database);
421
404
  }
422
405
  else {
@@ -443,7 +426,24 @@ class Document extends core_1.Client {
443
426
  }
444
427
  }
445
428
  this.assets = assets;
446
- return super.init();
429
+ super.init();
430
+ if (ignoreExtensions) {
431
+ if (ignoreExtensions === true || ignoreExtensions === this.moduleName || (0, types_1.isArray)(ignoreExtensions) && ignoreExtensions.includes(this.moduleName)) {
432
+ this._extensions = [];
433
+ }
434
+ else {
435
+ const extensions = this._extensions;
436
+ if ((0, types_1.isArray)(extensions)) {
437
+ if (typeof ignoreExtensions === 'string') {
438
+ this._extensions = extensions.filter(value => value !== ignoreExtensions);
439
+ }
440
+ else if ((0, types_1.isArray)(ignoreExtensions)) {
441
+ this._extensions = extensions.filter(value => !ignoreExtensions.includes(value));
442
+ }
443
+ }
444
+ }
445
+ }
446
+ return this;
447
447
  }
448
448
  abort(name) {
449
449
  if (this.aborted || name && this.settingsOf(name, 'abort') !== true) {
@@ -874,7 +874,7 @@ class Document extends core_1.Client {
874
874
  }
875
875
  for (let i = 0, j = 0, row; i < length; ++i) {
876
876
  if ((0, types_1.isPlainObject)(row = data[i])) {
877
- row['__index__'] ?? (row['__index__'] = ++j);
877
+ row.__index__ ?? (row.__index__ = ++j);
878
878
  if (output) {
879
879
  row = { ...output, ...row };
880
880
  }
@@ -900,10 +900,8 @@ class Document extends core_1.Client {
900
900
  return null;
901
901
  }
902
902
  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)) {
903
+ let transform = this.settings.transform, data;
904
+ if (!transform || !(0, types_1.isObject)(data = transform[type])) {
907
905
  return;
908
906
  }
909
907
  format = typeof format === 'string' ? format.trim().split(/\s*\+\s*/) : format.map(item => typeof item === 'string' ? item.trim() : '');
@@ -994,7 +992,7 @@ class Document extends core_1.Client {
994
992
  if (cacheData) {
995
993
  delete options.cacheData;
996
994
  }
997
- const imports = (_a = transform).imports || (_a.imports = {});
995
+ const imports = transform.imports || (transform.imports = {});
998
996
  const series = new transform_1.TransformSeries(type, code, options);
999
997
  series.init(this, __dirname);
1000
998
  let valid, excluded, userData, userImports, ignoreCache, storedLog, sourceFiles;
@@ -1132,7 +1130,7 @@ class Document extends core_1.Client {
1132
1130
  let transformer = CACHE_PACKAGE[plugin + username];
1133
1131
  if (!transformer) {
1134
1132
  try {
1135
- let pkg = this.resolveDir('package', plugin + '.js') || userImports?.[plugin] || imports[plugin] || PIR_PLUGINS[plugin];
1133
+ let pkg = this.resolveDir('package', plugin + '.js') || userImports?.[plugin] || imports[plugin] || util_1.IMPORTS[plugin];
1136
1134
  if ((0, types_1.isString)(pkg)) {
1137
1135
  const match = /^(@?\S+)@(\d+(?:\.\d+(?:\.\S+)?)?|[a-z]+)$/.exec(pkg);
1138
1136
  if (match) {
@@ -1143,10 +1141,13 @@ class Document extends core_1.Client {
1143
1141
  }
1144
1142
  else {
1145
1143
  transformer = context;
1146
- context = this;
1144
+ context = this; // eslint-disable-line @typescript-eslint/no-this-alias
1147
1145
  pkg = undefined;
1148
1146
  }
1149
- if (typeof transformer !== 'function' && typeof (transformer = transformer?.['default']) !== 'function') {
1147
+ if (transformer && typeof transformer !== 'function') {
1148
+ transformer = transformer.default;
1149
+ }
1150
+ if (typeof transformer !== 'function') {
1150
1151
  throw (0, types_1.errorMessage)(plugin, pkg || name, 'Invalid function');
1151
1152
  }
1152
1153
  if (pkg) {
@@ -1287,6 +1288,27 @@ class Document extends core_1.Client {
1287
1288
  }
1288
1289
  return this._dataSource || [];
1289
1290
  }
1291
+ set imports(value) {
1292
+ if (!(0, types_1.isPlainObject)(value)) {
1293
+ this._imports = null;
1294
+ return;
1295
+ }
1296
+ let imports = this._imports;
1297
+ if (imports) {
1298
+ this._imports = Object.assign(imports, value);
1299
+ }
1300
+ else {
1301
+ const username = this.host?.username;
1302
+ imports = username && this.settings.users?.[username]?.imports || this.module.imports;
1303
+ this._imports = Object.assign(this._imports || {}, (0, types_1.isPlainObject)(imports) ? imports : undefined, value);
1304
+ }
1305
+ }
1306
+ get imports() {
1307
+ if (!this._imports) {
1308
+ this.imports = {};
1309
+ }
1310
+ return this._imports;
1311
+ }
1290
1312
  get watching() {
1291
1313
  return this.assets.some(item => item.watch);
1292
1314
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.5.3",
3
+ "version": "0.7.0",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,12 +20,12 @@
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.7.0",
24
+ "@e-mc/db": "0.7.0",
25
+ "@e-mc/types": "0.7.0",
26
26
  "chalk": "4.1.2",
27
27
  "htmlparser2": "^9.0.0",
28
28
  "js-yaml": "^4.1.0",
29
- "picomatch": "^2.3.1"
29
+ "picomatch": "^3.0.1"
30
30
  }
31
31
  }
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;