Skip to content

Commit

Permalink
chore: make danger work with packaged api
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Jan 10, 2023
1 parent de8f843 commit 9adb7e0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
## Danger.js checks for Fluent UI N*
- script: |
yarn danger ci
DANGER_DISABLE_TRANSPILATION="true" yarn danger ci
displayName: danger
condition: eq(variables.isPR, true)
env:
Expand Down
7 changes: 4 additions & 3 deletions dangerfile.ts → dangerfile.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { danger, fail, warn, markdown, message } from 'danger';
// @ts-check

import { detectNonApprovedDependencies, checkChangelog, checkStorybookVersions } from '@fluentui/scripts-dangerjs';
const { danger, fail, warn, markdown, message } = require('danger');
const { detectNonApprovedDependencies, checkChangelog, checkStorybookVersions } = require('@fluentui/scripts-dangerjs');

/**
* This trick (of explicitly passing Danger JS utils as function arg, instead of importing them at places where needed)
* is necessary due to the magic DangerJS is doing with imports: https://spectrum.chat/danger/javascript/danger-js-actually-runs-your-imports-as-globals~0a005b56-31ec-4919-9a28-ced623949d4d
*/
const dangerJS = { danger, fail, warn, markdown, message };

export default async () => {
module.exports = async () => {
await checkChangelog(dangerJS);
await detectNonApprovedDependencies(dangerJS);
await checkStorybookVersions(dangerJS);
Expand Down
2 changes: 1 addition & 1 deletion scripts/dangerjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@fluentui/scripts-dangerjs",
"version": "0.0.1",
"private": true,
"main": "src/index.ts",
"main": "src/index.js",
"scripts": {
"format": "prettier -w --ignore-path ../../.prettierignore .",
"format:check": "yarn format -c",
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions scripts/dangerjs/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// require('@fluentui/scripts-babel/register');

require('@babel/register')({
extensions: ['.js', '.ts', '.tsx'],
ignore: [/node_modules/],
presets: [
[
'@babel/preset-env',
{
loose: true,
// modules: 'cjs',
targets: { node: 'current' },
},
],
['@babel/preset-typescript'],
],
});

module.exports = require('./api');

0 comments on commit 9adb7e0

Please sign in to comment.