Inline repo

This commit is contained in:
Alex
2024-04-19 21:42:48 -04:00
parent fb50ede688
commit 179cf83891
84 changed files with 9571 additions and 115 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env tsx
#!/usr/bin/env bun
import './build-local-rules';
import { promises as fs } from 'node:fs';
import { resolve, relative } from 'node:path';
import { isBuiltin } from 'node:module';
@ -7,7 +8,6 @@ import type { Plugin } from 'esbuild';
import { memoize } from 'lodash';
import { gray, green } from 'picocolors';
import { dependencies } from '../dist/package.json';
import { buildLocalRules } from '../src/build-local-rules';
import { dts } from './dts';
import { babelPlugin } from './modifier';
@ -124,9 +124,6 @@ function bundleType(source: string, output: string) {
}
async function main() {
console.log('Building local rules...');
await buildLocalRules();
console.log('Building type definitions...');
bundleType('./src/index.ts', './dist/index.d.ts');
bundleType('./src/prettier.ts', './dist/prettier.d.ts');

24
scripts/build-local-rules.ts Executable file
View File

@ -0,0 +1,24 @@
import { promises as fs } from 'node:fs';
import { camelCase } from 'lodash';
const files = (await fs.readdir('./src/rules'))
.filter(file => file.endsWith('.ts'))
.filter(file => file !== 'index.ts')
.map(file => file.slice(0, -3));
const entryFile = /* js */ `
import type { Rule } from 'eslint';
import type { ESLintUtils } from '@typescript-eslint/utils';
${files.map(file => `import ${camelCase(file)} from './${file}';`).join('\n')}
export const rules: Record<
string,
Rule.RuleModule | ESLintUtils.RuleModule<string, unknown[]>
> = {
${files.map(file => `'${file}': ${camelCase(file)},`).join('\n ')}
};
`.trim();
console.log('Building local rules...');
await fs.writeFile('./src/rules/index.ts', entryFile + '\n');

View File

@ -17,6 +17,9 @@ export function dts({
const entry: EntryPointConfig = {
filePath: source,
failOnClass: false,
libraries: {
importedLibraries: ['eslint-define-config'],
},
output: {
inlineDeclareExternals: false,
inlineDeclareGlobals: false,
@ -29,7 +32,7 @@ export function dts({
const generatedDts = generateDtsBundle([entry], {
preferredConfigPath: project,
followSymlinks: true,
followSymlinks: false,
});
ts.sys.writeFile(dist, generatedDts[0]);

View File

@ -1,24 +1,16 @@
#!/usr/bin/env tsx
import assert from 'node:assert';
import { readFileSync, promises as fs } from 'node:fs';
import { resolve, extname, relative } from 'node:path';
import { isBuiltin } from 'node:module';
import esbuild from 'esbuild';
import { readFileSync } from 'node:fs';
import { resolve, extname } from 'node:path';
import type { Loader, Plugin } from 'esbuild';
import * as babel from '@babel/core';
import { memoize } from 'lodash';
import { gray, green } from 'picocolors';
import type { types as t, types } from '@babel/core';
import { dependencies } from '../dist/package.json';
import { createMacro, type MacroHandler } from 'babel-plugin-macros';
import * as polyfill from '../src/polyfill';
import { buildLocalRules } from '../src/build-local-rules';
import { dts } from './dts';
const polyfills = Object.keys(polyfill);
const ENV = (process.env.NODE_ENV ??= 'production');
const PROD = ENV === 'production';
class HandlerMap {
map = new Map<string, MacroHandler>();