Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed May 18, 2024
1 parent 5744fda commit 835e643
Show file tree
Hide file tree
Showing 56 changed files with 1,261 additions and 1,464 deletions.
2 changes: 1 addition & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @type {import('mocha').MochaOptions}
*/
module.exports = {
require: ['source-map-support/register', 'ts-node/register'],
require: ['ts-node/register/transpile-only', 'tsconfig-paths/register'],
timeout: '2s',
color: true,
slow: '1s',
Expand Down
117 changes: 73 additions & 44 deletions .wallaby.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,69 +19,98 @@ module.exports = () => {
instrument: false,
},
{
pattern: './packages/*/data/*.json',
pattern: './packages/midnight-smoker/data/*.json',
instrument: false,
},
{
pattern: './packages/*/test/**/*.ts',
pattern: './packages/midnight-smoker/test/**/*.ts',
instrument: false,
},
{
pattern: './packages/*/test/**/fixture/**/*',
pattern: './packages/midnight-smoker/test/**/fixture/**/*',
instrument: false,
},
{
pattern: './packages/*/dist/**/*',
instrument: false,
},
'./packages/*/src/**/*.ts',
'./packages/*/package.json',
'!./packages/*/test/**/*.spec.ts',
'!./packages/docs/**/*',
'./packages/midnight-smoker/src/**/*.ts',
'./packages/midnight-smoker/package.json',
// './packages/midnight-smoker/src/package.json',
'!./packages/midnight-smoker/test/**/*.spec.ts',
// '!./packages/docs/**/*',
],
testFramework: 'mocha',
tests: [
'./packages/*/test/**/*.spec.ts',
'!./packages/*/test/e2e/**/*.spec.ts',
'!./packages/docs/test/**/*',
'./packages/midnight-smoker/test/**/*.spec.ts',
'!./packages/midnight-smoker/test/e2e/**/*.spec.ts',
// '!./packages/docs/test/**/*',
],
runMode: 'onsave',
workers: {recycle: true},
setup(wallaby) {
process.env.WALLABY = '1';
// const Module = require('module');
// const path = require('path');
// const {imports} = require(
// path.join(
// wallaby.projectCacheDir,
// 'packages',
// 'midnight-smoker',
// 'package.json',
// ),
// );
// const mappedImports = Object.fromEntries(
// Object.entries(imports).map(([key, value]) => [
// key,
// value.replace('dist', 'src'),
// ]),
// );

// const originalResolveFilename = Module._resolveFilename;
const minimatch = require('minimatch');
const path = require('path');
const Module = require('module');
const pkgJsonPath = path.join(
wallaby.projectCacheDir,
'packages',
'midnight-smoker',
'package.json',
);
const pkgJson = require(pkgJsonPath);
const mappedImports = Object.fromEntries(
Object.entries(pkgJson.imports).map(([key, value]) => [
key,
value.replace('dist', 'src'),
]),
);

const originalResolveFilename = Module._resolveFilename;

/**
* @param {string} request
* @param {unknown} _parent
* @returns {unknown}
*/
Module._resolveFilename = function (request, _parent) {
if (request in mappedImports) {
const newRequest = path.join(
wallaby.projectCacheDir,
'packages',
'midnight-smoker',
mappedImports[request],
);
return originalResolveFilename.call(this, newRequest, _parent);
} else if (request.startsWith('#')) {
// minimatch does not like a leading #
const trimmedRequest = request.slice(1);

// Module._resolveFilename = function (request, _parent) {
// console.log('Resolving %s', request);
// if (request in mappedImports) {
// const newRequest = path.join(
// wallaby.projectCacheDir,
// 'packages',
// 'midnight-smoker',
// mappedImports[request],
// );
// return originalResolveFilename.call(this, newRequest, _parent);
// }
const key = Object.keys(mappedImports).find((key) => {
return minimatch(trimmedRequest, key.slice(1));
});
if (key) {
const pattern = mappedImports[key];
// zap leading #
const trimmedKey = key.slice(1);
// where is the magic?
const magicIndex = trimmedKey.indexOf('*');
// strip everything that matches _before_ the magic
const wildname = trimmedRequest.slice(magicIndex);
const newValue = pattern.replace('*', wildname);
// given a request of `#foo/bar` matching `#foo/*`, this will be `bar`,
// which is injected into the value matching `#foo/*` (e.g., `./src/foo/*.js`)
// replace the magic with the rest of the request
const newRequest = path.join(
wallaby.projectCacheDir,
'packages',
'midnight-smoker',
newValue,
);
return originalResolveFilename.call(this, newRequest, _parent);
}
}

// return originalResolveFilename.call(this, request, _parent);
// };
return originalResolveFilename.call(this, request, _parent);
};
},
};
};
28 changes: 15 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/midnight-smoker/.config/tsconfig.paths.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"paths": {
"@midnight-smoker/plugin-default": ["../../plugin-default"],
"@midnight-smoker/test-util": ["../../test-util"],
"@midnight-smoker/plugin-default": ["../../plugin-default/src/index.js"],
"@midnight-smoker/test-util": ["../../test-util/src/index.js"],
"#cli": ["../src/cli/index.js"],
"#cli/*": ["../src/cli/*.js"],
"#component": ["../src/component/component/index.js"],
Expand Down
5 changes: 5 additions & 0 deletions packages/midnight-smoker/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../.config/tsconfig.workspace.json",
"files": [],
"include": ["dist/**/*"]
}
3 changes: 2 additions & 1 deletion packages/midnight-smoker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@
"types": "./dist/index.d.ts",
"files": [
"./bin",
"./data",
"./dist",
"./schema",
"./src",
"CHANGELOG.md",
"!**/*.tsbuildinfo",
"!jsconfig.json",
"!tsconfig.json"
],
"keywords": [
Expand Down Expand Up @@ -214,6 +214,7 @@
"@types/yargs": "17.0.32",
"memfs": "4.6.0",
"strip-ansi": "5.2.0",
"tsconfig-paths": "4.2.0",
"unexpected-eventemitter": "2.4.0",
"zod-to-json-schema": "3.22.3"
},
Expand Down
27 changes: 9 additions & 18 deletions packages/midnight-smoker/src/component/component/component.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
import {type ComponentKind, type ComponentKinds} from '#constants';
import {type PkgManager} from '#pkg-manager';
import {isBlessedPlugin} from '#plugin/blessed';
import {type PluginMetadata} from '#plugin/plugin-metadata';
import {type StaticPluginMetadata} from '#schema';
import {type Executor} from '#schema/executor';
import {type PkgManagerDef} from '#schema/pkg-manager-def';
import {type ReporterDef} from '#schema/reporter-def';
import {type SomeRule} from '#schema/rule';
import {type SomeRuleDef} from '#schema/rule-def';
import {type SomeReporter} from '../reporter/reporter';
// import Debug from 'debug';

// const debug = Debug('midnight-smoker:component');
export type ComponentObject<T extends ComponentKind> =
T extends typeof ComponentKinds.Rule
? SomeRule
: T extends typeof ComponentKinds.RuleDef
? SomeRuleDef
: T extends typeof ComponentKinds.PkgManagerDef
? PkgManagerDef
: T extends typeof ComponentKinds.PkgManager
? PkgManager
: T extends typeof ComponentKinds.ReporterDef
? ReporterDef
: T extends typeof ComponentKinds.Reporter
? SomeReporter
: T extends typeof ComponentKinds.Executor
? Executor
: never;
T extends typeof ComponentKinds.RuleDef
? SomeRuleDef
: T extends typeof ComponentKinds.PkgManagerDef
? PkgManagerDef
: T extends typeof ComponentKinds.ReporterDef
? ReporterDef
: T extends typeof ComponentKinds.Executor
? Executor
: never;

export interface Component<T extends ComponentKind = any>
extends StaticComponent<T> {
Expand Down
2 changes: 0 additions & 2 deletions packages/midnight-smoker/src/component/component/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export * from './component';

export * from './component-registry';

export * from './reified-component';

This file was deleted.

2 changes: 0 additions & 2 deletions packages/midnight-smoker/src/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export * from './executor';

export * from './pkg-manager';

export * from './reporter';

export * from './rule';

export * from './schema';
2 changes: 0 additions & 2 deletions packages/midnight-smoker/src/component/pkg-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export * as Util from 'midnight-smoker/util';

export {SemVer} from 'semver';

export * from './pkg-manager';

export * from './pkg-manager-loader';

export * from './pkg-manager-spec';
Expand Down
Loading

0 comments on commit 835e643

Please sign in to comment.