@e-mc/document 0.5.4 → 0.6.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Mile Square Park
1
+ Copyright 2023 Studio Trigger
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @e-mc/document
2
2
 
3
+ PEP 402 - Forever Ryuko
4
+
3
5
  ## LICENSE
4
6
 
5
7
  MIT
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/index.js CHANGED
@@ -11,24 +11,6 @@ const db_1 = require("@e-mc/db");
11
11
  const util_1 = require("@e-mc/document/util");
12
12
  const transform_1 = require("@e-mc/document/transform");
13
13
  const parse_1 = require("@e-mc/document/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 = {};
@@ -333,6 +315,7 @@ class Document extends core_1.Client {
333
315
  this._dataSource = null;
334
316
  this._transformConfig = null;
335
317
  this._mimeMap = null;
318
+ this._imports = null;
336
319
  const transform = this.settingsOf('transform', 'cache');
337
320
  if (transform !== undefined) {
338
321
  this.customize({ transform });
@@ -364,7 +347,10 @@ class Document extends core_1.Client {
364
347
  }
365
348
  if ((0, types_1.isPlainObject)(pages)) {
366
349
  let mimeMap;
367
- if (!(0, types_1.isPlainObject)(mimeMap = pages[baseUrl])) {
350
+ if ((0, types_1.isPlainObject)(mimeMap = pages[baseUrl])) {
351
+ mimeMap = { ...mimeMap };
352
+ }
353
+ else {
368
354
  const items = [];
369
355
  for (const pattern in pages) {
370
356
  const item = pages[pattern];
@@ -387,8 +373,8 @@ class Document extends core_1.Client {
387
373
  items.sort((a, b) => typeof a.ordinal === 'number' && typeof b.ordinal === 'number' ? a.ordinal - b.ordinal : 0);
388
374
  mimeMap = items.reduce((a, b) => Object.assign(a, b), {});
389
375
  }
390
- else {
391
- mimeMap = items[0];
376
+ else if (items.length) {
377
+ mimeMap = { ...items[0] };
392
378
  }
393
379
  }
394
380
  if (mimeMap) {
@@ -896,10 +882,8 @@ class Document extends core_1.Client {
896
882
  return null;
897
883
  }
898
884
  async transform(type, code, format, options = {}) {
899
- var _a;
900
- let transform = this.settings.transform;
901
- const data = transform?.[type];
902
- if (!(0, types_1.isObject)(data)) {
885
+ let transform = this.settings.transform, data;
886
+ if (!transform || !(0, types_1.isObject)(data = transform[type])) {
903
887
  return;
904
888
  }
905
889
  format = typeof format === 'string' ? format.trim().split(/\s*\+\s*/) : format.map(item => typeof item === 'string' ? item.trim() : '');
@@ -990,7 +974,7 @@ class Document extends core_1.Client {
990
974
  if (cacheData) {
991
975
  delete options.cacheData;
992
976
  }
993
- const imports = (_a = transform).imports || (_a.imports = {});
977
+ const imports = transform.imports || (transform.imports = {});
994
978
  const series = new transform_1.TransformSeries(type, code, options);
995
979
  series.init(this, __dirname);
996
980
  let valid, excluded, userData, userImports, ignoreCache, storedLog, sourceFiles;
@@ -1127,8 +1111,8 @@ class Document extends core_1.Client {
1127
1111
  let transformer = CACHE_PACKAGE[plugin + username];
1128
1112
  if (!transformer) {
1129
1113
  try {
1130
- let pkg = this.resolveDir('package', plugin + '.js') || userImports?.[plugin] || imports[plugin] || PIR_PLUGINS[plugin];
1131
- if (pkg) {
1114
+ let pkg = this.resolveDir('package', plugin + '.js') || userImports?.[plugin] || imports[plugin] || util_1.IMPORTS[plugin];
1115
+ if ((0, types_1.isString)(pkg)) {
1132
1116
  const match = /^(@?\S+)@(\d+(?:\.\d+(?:\.\S+)?)?|[a-z]+)$/.exec(pkg);
1133
1117
  if (match) {
1134
1118
  pkg = match[1];
@@ -1139,12 +1123,13 @@ class Document extends core_1.Client {
1139
1123
  else {
1140
1124
  transformer = context;
1141
1125
  context = this;
1126
+ pkg = undefined;
1127
+ }
1128
+ if (transformer && typeof transformer !== 'function') {
1129
+ transformer = transformer.default;
1142
1130
  }
1143
1131
  if (typeof transformer !== 'function') {
1144
- transformer && (transformer = transformer.default);
1145
- if (typeof transformer !== 'function') {
1146
- throw (0, types_1.errorMessage)(plugin, pkg || name, 'Invalid function');
1147
- }
1132
+ throw (0, types_1.errorMessage)(plugin, pkg || name, 'Invalid function');
1148
1133
  }
1149
1134
  if (pkg) {
1150
1135
  CACHE_PACKAGE[plugin + username] = transformer;
@@ -1284,6 +1269,27 @@ class Document extends core_1.Client {
1284
1269
  }
1285
1270
  return this._dataSource || [];
1286
1271
  }
1272
+ set imports(value) {
1273
+ if (!(0, types_1.isPlainObject)(value)) {
1274
+ this._imports = null;
1275
+ return;
1276
+ }
1277
+ let imports = this._imports;
1278
+ if (imports) {
1279
+ this._imports = Object.assign(imports, value);
1280
+ }
1281
+ else {
1282
+ const username = this.host?.username;
1283
+ imports = username && this.settings.users?.[username]?.imports || this.module.imports;
1284
+ this._imports = Object.assign(this._imports || {}, (0, types_1.isPlainObject)(imports) ? imports : undefined, value);
1285
+ }
1286
+ }
1287
+ get imports() {
1288
+ if (!this._imports) {
1289
+ this.imports = {};
1290
+ }
1291
+ return this._imports;
1292
+ }
1287
1293
  get watching() {
1288
1294
  return this.assets.some(item => item.watch);
1289
1295
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.5.4",
3
+ "version": "0.6.1",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git+https://github.com/anpham6/e-mc.git",
12
+ "url": "https://github.com/anpham6/e-mc.git",
13
13
  "directory": "src/document"
14
14
  },
15
15
  "keywords": [
@@ -20,9 +20,9 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.5.4",
24
- "@e-mc/db": "0.5.4",
25
- "@e-mc/types": "0.5.4",
23
+ "@e-mc/core": "0.6.1",
24
+ "@e-mc/db": "0.6.1",
25
+ "@e-mc/types": "0.6.1",
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 = {};
@@ -312,6 +312,6 @@ class SourceMap {
312
312
  return this[kMap];
313
313
  }
314
314
  }
315
+ exports.SourceMap = SourceMap;
315
316
  _d = kMap;
316
317
  SourceMap.RE_SOURCE_MAPPING_URL = /(?:\r\n|\n)*(?:(\/\/)|(\/\*))\s*[#@][ ]+sourceMappingURL=(data:[^,]+,)?(\S+)\s*(\*\/)?\r?\n?/g;
317
- 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("@e-mc/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;