@tsslint/config 0.0.12 → 0.0.13

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/index.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- export * from './lib/build';
2
- export * from './lib/watch';
3
1
  export * from './lib/types';
4
- import type { Config, Rule } from './lib/types';
2
+ import type { Config } from './lib/types';
5
3
  export declare function defineConfig(config: Config): Config;
6
- export declare function defineRule(rule: Rule): Rule;
package/index.js CHANGED
@@ -14,16 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.defineRule = exports.defineConfig = void 0;
18
- __exportStar(require("./lib/build"), exports);
19
- __exportStar(require("./lib/watch"), exports);
17
+ exports.defineConfig = void 0;
20
18
  __exportStar(require("./lib/types"), exports);
21
19
  function defineConfig(config) {
22
20
  return config;
23
21
  }
24
22
  exports.defineConfig = defineConfig;
25
- function defineRule(rule) {
26
- return rule;
27
- }
28
- exports.defineRule = defineRule;
29
23
  //# sourceMappingURL=index.js.map
package/lib/watch.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare function watchConfigFile(configFilePath: string, onBuild: (config
5
5
  bundle: true;
6
6
  sourcemap: true;
7
7
  outfile: string;
8
- format: "cjs";
8
+ format: "esm";
9
9
  platform: "node";
10
10
  plugins: {
11
11
  name: string;
package/lib/watch.js CHANGED
@@ -2,16 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.watchConfigFile = void 0;
4
4
  const esbuild = require("esbuild");
5
- const path = require("path");
5
+ const _path = require("path");
6
+ const fs = require("fs");
6
7
  async function watchConfigFile(configFilePath, onBuild, watch = true, createHash = btoa) {
7
- const outDir = path.resolve(__dirname, '..', '..', '.tsslint');
8
- const outFileName = createHash(path.relative(outDir, configFilePath)) + '.cjs';
9
- const outFile = path.join(outDir, outFileName);
10
- const resultHandler = (result) => {
8
+ const outDir = _path.resolve(configFilePath, '..', 'node_modules', '.tsslint');
9
+ const outFileName = createHash(_path.relative(outDir, configFilePath)) + '.mjs';
10
+ const outFile = _path.join(outDir, outFileName);
11
+ const resultHandler = async (result) => {
11
12
  let config;
12
13
  if (!result.errors.length) {
13
14
  try {
14
- config = require(outFile).default;
15
+ config = (await import(outFile)).default;
15
16
  delete require.cache[outFile];
16
17
  }
17
18
  catch (e) {
@@ -20,20 +21,27 @@ async function watchConfigFile(configFilePath, onBuild, watch = true, createHash
20
21
  }
21
22
  onBuild(config, result);
22
23
  };
24
+ const cacheDir = _path.resolve(outDir, 'http_resources');
25
+ const cachePathToOriginalPath = new Map();
23
26
  const ctx = await esbuild.context({
24
27
  entryPoints: [configFilePath],
25
28
  bundle: true,
26
29
  sourcemap: true,
27
30
  outfile: outFile,
28
- format: 'cjs',
31
+ format: 'esm',
29
32
  platform: 'node',
30
33
  plugins: [{
31
34
  name: 'tsslint',
32
35
  setup(build) {
33
- build.onResolve({ filter: /.*/ }, args => {
34
- if (!args.path.endsWith('.ts')) {
36
+ build.onResolve({ filter: /^https?:\/\// }, ({ path }) => {
37
+ const cachePath = _path.join(cacheDir, createHash(path));
38
+ cachePathToOriginalPath.set(cachePath, path);
39
+ return { path: cachePath, namespace: 'http-url' };
40
+ });
41
+ build.onResolve({ filter: /.*/ }, ({ path, resolveDir }) => {
42
+ if (!path.endsWith('.ts')) {
35
43
  try {
36
- const jsPath = require.resolve(args.path, { paths: [args.resolveDir] });
44
+ const jsPath = require.resolve(path, { paths: [resolveDir] });
37
45
  return {
38
46
  path: jsPath,
39
47
  external: true,
@@ -43,6 +51,26 @@ async function watchConfigFile(configFilePath, onBuild, watch = true, createHash
43
51
  }
44
52
  return {};
45
53
  });
54
+ build.onLoad({ filter: /.*/, namespace: 'http-url' }, async ({ path: cachePath }) => {
55
+ const path = cachePathToOriginalPath.get(cachePath);
56
+ if (fs.existsSync(cachePath)) {
57
+ return {
58
+ contents: fs.readFileSync(cachePath, 'utf8'),
59
+ loader: 'ts',
60
+ };
61
+ }
62
+ const response = await fetch(path);
63
+ if (!response.ok) {
64
+ throw new Error(`Failed to load ${path}`);
65
+ }
66
+ const text = await response.text();
67
+ fs.mkdirSync(cacheDir, { recursive: true });
68
+ fs.writeFileSync(cachePath, text, 'utf8');
69
+ return {
70
+ contents: text,
71
+ loader: path.substring(path.lastIndexOf('.') + 1),
72
+ };
73
+ });
46
74
  if (watch) {
47
75
  build.onEnd(resultHandler);
48
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/config",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -14,5 +14,5 @@
14
14
  "dependencies": {
15
15
  "esbuild": "^0.19.0"
16
16
  },
17
- "gitHead": "f6737f340ad02a90054dbdc0514b5c253bb695e7"
17
+ "gitHead": "ebb2ecf9dadc0ebccd1859af973cb8fbbd07c83d"
18
18
  }