diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 76fbe4f636ad17..d81234ecd9f86f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -124,38 +124,38 @@ jobs: retention-days: 1 if: ${{ github.event_name == 'pull_request' }} - # dangerbot: - # runs-on: ubuntu-latest - # if: github.repository == 'DefinitelyTyped/DefinitelyTyped' && github.event_name == 'pull_request' - - # needs: - # - test - - # steps: - # - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - # - uses: ./.github/actions/setup-for-scripts - - # - name: Get suggestions dir - # id: suggestions-dir - # run: echo "path=$(node ./scripts/get-suggestions-dir.js)" >> "$GITHUB_OUTPUT" - - # - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 - # with: - # path: ${{ steps.suggestions-dir.outputs.path }} - # merge-multiple: true - - # - name: 'Run Danger' - # env: - # # See https://github.com/danger/danger-js/issues/1042 - # DANGER_GITHUB_API_BASE_URL: 'https://api.github.com' - - # # Danger failing (for example through rate-limiting) shouldn't fail the build - # run: | - # # Exposing this token is safe because the user of it has no other public repositories - # # and has no permission to modify this repository. See #62638 for the discussion. - # TOKEN='ghp_i5wtj1l2AbpFv3OU96w6R' - # TOKEN+='On3bHOkcV2AmVY6' - # DANGER_GITHUB_API_TOKEN=$TOKEN pnpm danger ci || $( exit 0 ) + dangerbot: + runs-on: ubuntu-latest + if: github.repository == 'DefinitelyTyped/DefinitelyTyped' && github.event_name == 'pull_request' + + needs: + - test + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: ./.github/actions/setup-for-scripts + + - name: Get suggestions dir + id: suggestions-dir + run: echo "path=$(node ./scripts/get-suggestions-dir.js)" >> "$GITHUB_OUTPUT" + + - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 + with: + path: ${{ steps.suggestions-dir.outputs.path }} + merge-multiple: true + + - name: 'Run Danger' + env: + # See https://github.com/danger/danger-js/issues/1042 + DANGER_GITHUB_API_BASE_URL: 'https://api.github.com' + + # Danger failing (for example through rate-limiting) shouldn't fail the build + run: | + # Exposing this token is safe because the user of it has no other public repositories + # and has no permission to modify this repository. See #62638 for the discussion. + TOKEN='ghp_i5wtj1l2AbpFv3OU96w6R' + TOKEN+='On3bHOkcV2AmVY6' + DANGER_GITHUB_API_TOKEN=$TOKEN pnpm danger ci || $( exit 0 ) scripts: runs-on: ubuntu-latest diff --git a/dangerfile.ts b/dangerfile.ts index 9c4dae8a09717d..813e72c9af484f 100644 --- a/dangerfile.ts +++ b/dangerfile.ts @@ -1,9 +1,9 @@ -import fs = require("fs"); -import os = require("os"); -import path = require("path"); -import cp = require("child_process"); import { mangleScopedPackage, suggestionsDir } from "@definitelytyped/utils"; import { danger, fail, markdown } from "danger"; +import cp from "node:child_process"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; const lines: string[] = []; const missingProperty = /module exports a property named '(.+?)', which is missing/; @@ -129,7 +129,7 @@ if (dprintErrors.length > 0) { "## Formatting errors", "", codeBlock, - ...dprintErrors.join("\n\n"), + dprintErrors.join("\n\n"), codeBlock, ]; diff --git a/package.json b/package.json index b47e60ab53207a..020ffd004d69ca 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@definitelytyped/header-parser": "latest", "@definitelytyped/typescript-versions": "latest", "@definitelytyped/utils": "latest", - "danger": "^11.2.3", + "danger": "^13.0.5", "dprint": "^0.49.0", "eslint-plugin-jsdoc": "^44.2.7", "husky": "^8.0.3", diff --git a/types/meteor/meteor.d.ts b/types/meteor/meteor.d.ts index cb93e1bf27455d..90be73b99ba757 100644 --- a/types/meteor/meteor.d.ts +++ b/types/meteor/meteor.d.ts @@ -235,6 +235,31 @@ declare module 'meteor/meteor' { * @param func The function to run */ function defer(func: Function): void; + + /** + * Wrap a function so that it only runs in background in specified environments.. + * @param func The function to wrap + * @param options An object with an `on` property that is an array of environment names: `"development"`, `"production"`, and/or `"test"`. + */ + function deferrable( + func: () => T, + options: { on: Array<"development" | "production" | "test"> } + ): T | void; + + /** + * Wrap a function to run in the background in development (similar to Meteor.isDevelopment ? Meteor.defer(fn) : Meteor.startup(fn)). + * @param func The function to wrap + */ + function deferDev( + func: () => T + ): T | void; + /** + * Wrap a function to run in the background in production (similar to Meteor.isProduction ? Meteor.defer(fn) : Meteor.startup(fn)). + * @param func The function to wrap + */ + function deferProd( + func: () => T + ): T | void; /** Timeout **/ /** utils **/ diff --git a/types/meteor/test/meteor-tests.ts b/types/meteor/test/meteor-tests.ts index 13ce5150430be0..853bbd39c7e394 100644 --- a/types/meteor/test/meteor-tests.ts +++ b/types/meteor/test/meteor-tests.ts @@ -88,6 +88,12 @@ namespace MeteorTests { .aggregate([{ $group: { _id: null, names: { $addToSet: '$name' } } }]) .toArray() .then(); + + Meteor.deferrable( + () => console.log('This is deferred until after startup.'), + {on: ['development', 'test']}, + ) + }); } @@ -398,6 +404,7 @@ namespace MeteorTests { if (Meteor.isServer) { Logs.remove({}); Players.remove({ karma: { $lt: -2 } }); + Meteor.defer(() => console.log('Old low-karma players removed from the Players collection.')); } }); @@ -1203,6 +1210,14 @@ namespace MeteorTests { Rooms._dropIndex('indexName'); } + Meteor.deferDev(() => { + console.log('This is a development-only deferred function.'); + }); + + Meteor.deferProd(() => { + console.log('This is a production-only deferred function.'); + }); + (async function() { await Rooms.dropIndexAsync('indexName'); })();