Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build system rework #1941

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier"
],
"ignorePatterns": [
"dist",
"node_modules",
"jest.config.base.js",
"jest.bench.config.js",
"jest.config.js",
"babel.config.js",
"build.js",
"update-pkg.js"
"plugin:@typescript-eslint/recommended"
],
"env": {
"node": true,
"browser": true
},
"ignorePatterns": ["dist", "node_modules"],
"rules": {
"no-var": "error",
"prefer-const": "warn",
Expand All @@ -36,5 +29,13 @@
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off"
}
},
"overrides": [
{
"files": ["*.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
}
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

4 changes: 0 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// jest.config.js
const base = require('./jest.config.base.js')

module.exports = {
...base,
projects: ['<rootDir>/packages/*/jest.config.js'],
}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@
},
"scripts": {
"lint:fix": "pnpm lint --fix",
"lint": "eslint . --ext .ts,.tsx",
"verify": "prettier --check . && pnpm lint",
"lint": "eslint . --ext .ts,.js",
"verify": "prettier --check . && pnpm lint && pnpm verify:types",
"verify:types": "tsc --build tsconfig.json --verbose --force",
"format": "prettier --write .",
"build": "pnpm -r --stream build",
"update-main-to-dist": "pnpm -r --stream update-main-to-dist",
"test": "LOG_ENABLED=false NODE_ENV=development ./packages/dev-infra/with-test-redis-and-db.sh pnpm --stream -r test",
"test:withFlags": "LOG_ENABLED=false NODE_ENV=development ./packages/dev-infra/with-test-redis-and-db.sh pnpm --stream -r test --",
"build": "npm-run-all build:tsc build:packages",
"build:tsc": "NODE_ENV=production tsc --build tsconfig.build.json --verbose --force",
"build:packages": "NODE_ENV=production pnpm run --recursive build",
"test": "LOG_ENABLED=false NODE_ENV=development ./packages/dev-infra/with-test-redis-and-db.sh jest",
"test:withFlags": "LOG_ENABLED=false NODE_ENV=development ./packages/dev-infra/with-test-redis-and-db.sh jest --",
"changeset": "changeset",
"release": "pnpm build && changeset publish",
"version-packages": "changeset version && git add ."
},
"devDependencies": {
"@babel/core": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@npmcli/package-json": "^3.0.0",
"@swc/core": "^1.3.42",
"@swc/jest": "^0.2.24",
"@types/jest": "^28.1.4",
Expand All @@ -42,8 +41,9 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"handlebars-jest": "^1.0.0",
"jest": "^28.1.2",
"jest": "^29.7.0",
"node-gyp": "^9.3.1",
"npm-run-all": "^4.1.5",
"pino-pretty": "^9.1.0",
"prettier": "^2.7.1",
"prettier-config-standard": "^5.0.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/api/babel.config.js

This file was deleted.

15 changes: 0 additions & 15 deletions packages/api/build.js

This file was deleted.

7 changes: 4 additions & 3 deletions packages/api/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const base = require('../../jest.config.base.js')

/** @type {import('jest').Config} */
module.exports = {
...base,
displayName: 'API',
transform: { '^.+\\.(t|j)s?$': '@swc/jest' },
transformIgnorePatterns: [`<rootDir>/node_modules/(?!get-port)`],
setupFiles: ['<rootDir>/jest.setup.ts'],
}
20 changes: 20 additions & 0 deletions packages/api/jest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
declare namespace jest {
// eslint-disable-next-line
interface Matchers<R, T = {}> {
toBeModerationResult(
expected: ModerationBehaviorResult | undefined,
context: string,
stringifiedResult: string,
ignoreCause?: boolean,
): R
}

interface Expect {
toBeModerationResult(
expected: ModerationBehaviorResult | undefined,
context: string,
stringifiedResult: string,
ignoreCause?: boolean,
): void
}
}
79 changes: 79 additions & 0 deletions packages/api/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { ModerationBehaviorResult } from './definitions/moderation-behaviors'
import { ModerationUI } from './src'

expect.extend({
toBeModerationResult(
actual: ModerationUI,
expected: ModerationBehaviorResult | undefined,
context: string,
stringifiedResult: string,
ignoreCause = false,
) {
const fail = (msg: string) => ({
pass: false,
message: () => `${msg}. Full result: ${stringifiedResult}`,
})
let cause = actual.cause?.type as string
if (actual.cause?.type === 'label') {
cause = `label:${actual.cause.labelDef.id}`
} else if (actual.cause?.type === 'muted') {
if (actual.cause.source.type === 'list') {
cause = 'muted-by-list'
}
} else if (actual.cause?.type === 'blocking') {
if (actual.cause.source.type === 'list') {
cause = 'blocking-by-list'
}
}
if (!expected) {
if (!ignoreCause && actual.cause) {
return fail(`${context} expected to be a no-op, got ${cause}`)
}
if (actual.alert) {
return fail(`${context} expected to be a no-op, got alert=true`)
}
if (actual.blur) {
return fail(`${context} expected to be a no-op, got blur=true`)
}
if (actual.filter) {
return fail(`${context} expected to be a no-op, got filter=true`)
}
if (actual.noOverride) {
return fail(`${context} expected to be a no-op, got noOverride=true`)
}
} else {
if (!ignoreCause && cause !== expected.cause) {
return fail(`${context} expected to be ${expected.cause}, got ${cause}`)
}
if (!!actual.alert !== !!expected.alert) {
return fail(
`${context} expected to be alert=${expected.alert || false}, got ${
actual.alert || false
}`,
)
}
if (!!actual.blur !== !!expected.blur) {
return fail(
`${context} expected to be blur=${expected.blur || false}, got ${
actual.blur || false
}`,
)
}
if (!!actual.filter !== !!expected.filter) {
return fail(
`${context} expected to be filter=${expected.filter || false}, got ${
actual.filter || false
}`,
)
}
if (!!actual.noOverride !== !!expected.noOverride) {
return fail(
`${context} expected to be noOverride=${
expected.noOverride || false
}, got ${actual.noOverride || false}`,
)
}
}
return { pass: true, message: () => '' }
},
})
13 changes: 4 additions & 9 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@
"url": "https://github.com/bluesky-social/atproto",
"directory": "packages/api"
},
"main": "src/index.ts",
"publishConfig": {
"main": "dist/index.js",
"types": "dist/index.d.ts"
},
"type": "commonjs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"codegen": "pnpm docgen && node ./scripts/generate-code.mjs && lex gen-api ./src/client ../../lexicons/com/atproto/*/* ../../lexicons/app/bsky/*/*",
"docgen": "node ./scripts/generate-docs.mjs",
"build": "node ./build.js",
"postbuild": "tsc --build tsconfig.build.json",
"update-main-to-dist": "node ../../update-main-to-dist.js packages/api",
"test": "jest",
"bench": "jest --config jest.bench.config.js",
"bench:profile": "node --inspect-brk ../../node_modules/.bin/jest --config jest.bench.config.js"
Expand All @@ -36,11 +31,11 @@
"@atproto/xrpc": "workspace:^",
"multiformats": "^9.9.0",
"tlds": "^1.234.0",
"tslib": "^2.6.2",
"typed-emitter": "^2.1.0",
"zod": "^3.21.4"
},
"devDependencies": {
"@atproto/lex-cli": "workspace:^",
"@atproto/dev-env": "workspace:^",
"common-tags": "^1.8.2"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/api/tests/profile-moderation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ describe('Post moderation behaviors', () => {
suiteRunner.moderationOpts(scenario),
)
expect(res.account).toBeModerationResult(
// @ts-expect-error TODO FIXME
scenario.behaviors.account,
'account',
JSON.stringify(res, null, 2),
)
expect(res.profile).toBeModerationResult(
// @ts-expect-error TODO FIXME
scenario.behaviors.profile,
'profile content',
JSON.stringify(res, null, 2),
Expand Down
82 changes: 2 additions & 80 deletions packages/api/tests/util/moderation-behavior.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,10 @@
import { ModerationUI, ModerationOpts, ComAtprotoLabelDefs } from '../../src'
import type {
ModerationBehaviors,
ModerationBehaviorScenario,
ModerationBehaviorResult,
ModerationBehaviors,
} from '../../definitions/moderation-behaviors'
import { ComAtprotoLabelDefs, ModerationOpts } from '../../src'
import { mock as m } from './index'

expect.extend({
toBeModerationResult(
actual: ModerationUI,
expected: ModerationBehaviorResult | undefined,
context: string,
stringifiedResult: string,
ignoreCause = false,
) {
const fail = (msg: string) => ({
pass: false,
message: () => `${msg}. Full result: ${stringifiedResult}`,
})
let cause = actual.cause?.type as string
if (actual.cause?.type === 'label') {
cause = `label:${actual.cause.labelDef.id}`
} else if (actual.cause?.type === 'muted') {
if (actual.cause.source.type === 'list') {
cause = 'muted-by-list'
}
} else if (actual.cause?.type === 'blocking') {
if (actual.cause.source.type === 'list') {
cause = 'blocking-by-list'
}
}
if (!expected) {
if (!ignoreCause && actual.cause) {
return fail(`${context} expected to be a no-op, got ${cause}`)
}
if (actual.alert) {
return fail(`${context} expected to be a no-op, got alert=true`)
}
if (actual.blur) {
return fail(`${context} expected to be a no-op, got blur=true`)
}
if (actual.filter) {
return fail(`${context} expected to be a no-op, got filter=true`)
}
if (actual.noOverride) {
return fail(`${context} expected to be a no-op, got noOverride=true`)
}
} else {
if (!ignoreCause && cause !== expected.cause) {
return fail(`${context} expected to be ${expected.cause}, got ${cause}`)
}
if (!!actual.alert !== !!expected.alert) {
return fail(
`${context} expected to be alert=${expected.alert || false}, got ${
actual.alert || false
}`,
)
}
if (!!actual.blur !== !!expected.blur) {
return fail(
`${context} expected to be blur=${expected.blur || false}, got ${
actual.blur || false
}`,
)
}
if (!!actual.filter !== !!expected.filter) {
return fail(
`${context} expected to be filter=${expected.filter || false}, got ${
actual.filter || false
}`,
)
}
if (!!actual.noOverride !== !!expected.noOverride) {
return fail(
`${context} expected to be noOverride=${
expected.noOverride || false
}, got ${actual.noOverride || false}`,
)
}
}
return { pass: true, message: () => '' }
},
})

export class ModerationBehaviorSuiteRunner {
constructor(public suite: ModerationBehaviors) {}

Expand Down
8 changes: 6 additions & 2 deletions packages/api/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"extends": "./tsconfig.json",
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
"extends": "../../tsconfig/base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["./src"]
}
13 changes: 4 additions & 9 deletions packages/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist", // Your outDir,
"emitDeclarationOnly": true
},
"include": ["./src"],
"include": [],
"references": [
{ "path": "../xrpc/tsconfig.build.json" },
{ "path": "../lex-cli/tsconfig.build.json" }
{ "path": "./tsconfig.build.json" },
{ "path": "./tsconfig.scripts.json" },
{ "path": "./tsconfig.test.json" }
]
}
Loading
Loading