@lsbjordao/type-taxon-script 1.1.16 → 1.1.18

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.
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,8 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
15
  const fs_1 = __importDefault(require("fs"));
39
16
  const path_1 = __importDefault(require("path"));
17
+ const child_process_1 = require("child_process");
40
18
  const fast_glob_1 = __importDefault(require("fast-glob"));
41
19
  const n3_1 = require("n3");
20
+ const tscBin = require.resolve('typescript/bin/tsc');
42
21
  const { namedNode, literal, quad, blankNode } = n3_1.DataFactory;
43
22
  const NS = {
44
23
  tts: 'https://tts.example.org/ontology/',
@@ -147,19 +126,46 @@ function primitiveToLiteral(value) {
147
126
  return literal(String(value), xsd('boolean'));
148
127
  }
149
128
  function importModules(pattern) {
129
+ var _a, _b;
150
130
  return __awaiter(this, void 0, void 0, function* () {
151
- const files = yield (0, fast_glob_1.default)(pattern, { absolute: true });
131
+ const tsFiles = yield (0, fast_glob_1.default)(pattern, { absolute: true });
132
+ if (tsFiles.length === 0)
133
+ return [];
134
+ const tempDir = path_1.default.join(process.cwd(), 'temp');
135
+ fs_1.default.mkdirSync(tempDir, { recursive: true });
136
+ const tempTsConfigPath = path_1.default.join(tempDir, 'tsconfig.ontology.json');
137
+ fs_1.default.writeFileSync(tempTsConfigPath, JSON.stringify({
138
+ compilerOptions: { target: 'ES2016', module: 'commonjs', esModuleInterop: true, skipLibCheck: true },
139
+ files: tsFiles
140
+ }), 'utf-8');
141
+ try {
142
+ (0, child_process_1.execSync)(`node "${tscBin}" -p "${tempTsConfigPath}"`);
143
+ }
144
+ catch (e) {
145
+ fs_1.default.unlinkSync(tempTsConfigPath);
146
+ throw new Error(((_a = e.stdout) === null || _a === void 0 ? void 0 : _a.toString()) || ((_b = e.stderr) === null || _b === void 0 ? void 0 : _b.toString()) || e.message);
147
+ }
148
+ fs_1.default.unlinkSync(tempTsConfigPath);
152
149
  const modules = [];
153
- for (const file of files) {
154
- const mod = yield Promise.resolve(`${toFileUrl(file)}`).then(s => __importStar(require(s)));
155
- modules.push({ file, mod });
150
+ const jsFiles = [];
151
+ for (const file of tsFiles) {
152
+ const jsFile = file.replace(/\.ts$/, '.js');
153
+ jsFiles.push(jsFile);
154
+ modules.push({ file, mod: require(jsFile) });
156
155
  }
156
+ for (const jsFile of jsFiles) {
157
+ try {
158
+ fs_1.default.unlinkSync(jsFile);
159
+ }
160
+ catch ( /* ignore */_c) { /* ignore */ }
161
+ }
162
+ try {
163
+ fs_1.default.rmdirSync(tempDir);
164
+ }
165
+ catch ( /* ignore if not empty */_d) { /* ignore if not empty */ }
157
166
  return modules;
158
167
  });
159
168
  }
160
- function toFileUrl(filePath) {
161
- return `file://${path_1.default.resolve(filePath)}`;
162
- }
163
169
  function inferRangeFromValue(value) {
164
170
  if (typeof value === 'number')
165
171
  return xsd('decimal');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsbjordao/type-taxon-script",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "author": "Lucas Jordão <tucarj@gmail.com> & André Eppinghaus <andreeppinghaus@gmail.com> & Vicente Calfo <vicentecalfo@gmail.com>",
5
5
  "license": "ISC",
6
6
  "description": "TypeTaxonScript",