diff --git a/packages/grafana-alerting/package.json b/packages/grafana-alerting/package.json index 0d4dfa1c746..a777abcc684 100644 --- a/packages/grafana-alerting/package.json +++ b/packages/grafana-alerting/package.json @@ -54,11 +54,11 @@ "scripts": { "build": "tsc -p ./tsconfig.build.json && rollup -c rollup.config.ts --configPlugin esbuild", "bundle": "rollup -c rollup.config.ts --configPlugin esbuild", - "clean": "rimraf ./dist ./compiled ./unstable ./package.tgz", + "clean": "rimraf ./dist ./compiled ./unstable ./testing ./package.tgz", "typecheck": "tsc --emitDeclarationOnly false --noEmit", "codegen": "rtk-query-codegen-openapi ./scripts/codegen.ts", - "prepack": "cp package.json package.json.bak && ALIAS_PACKAGE_NAME=unstable node ../../scripts/prepare-npm-package.js", - "postpack": "mv package.json.bak package.json && rimraf ./unstable" + "prepack": "cp package.json package.json.bak && ALIAS_PACKAGE_NAME=testing,unstable node ../../scripts/prepare-npm-package.js", + "postpack": "mv package.json.bak package.json && rimraf ./unstable ./testing" }, "devDependencies": { "@grafana/test-utils": "workspace:*", diff --git a/packages/grafana-alerting/rollup.config.ts b/packages/grafana-alerting/rollup.config.ts index 1d9b0e1ae40..1638793c474 100644 --- a/packages/grafana-alerting/rollup.config.ts +++ b/packages/grafana-alerting/rollup.config.ts @@ -18,4 +18,9 @@ export default [ output: [cjsOutput(pkg), esmOutput(pkg, 'grafana-alerting')], treeshake: false, }, + { + input: 'src/testing.ts', + plugins, + output: [cjsOutput(pkg), esmOutput(pkg, 'grafana-alerting')], + }, ]; diff --git a/packages/grafana-alerting/src/testing.ts b/packages/grafana-alerting/src/testing.ts index 3de18f49993..b3a0d024b32 100644 --- a/packages/grafana-alerting/src/testing.ts +++ b/packages/grafana-alerting/src/testing.ts @@ -4,3 +4,6 @@ export * from './grafana/api/v0alpha1/mocks/handlers'; // export mocks and factories export * from './grafana/api/v0alpha1/mocks/fakes/common'; export * from './grafana/api/v0alpha1/mocks/fakes/Receivers'; + +// scenarios +export * from './grafana/contactPoints/components/ContactPointSelector/ContactPointSelector.test.scenario'; diff --git a/scripts/prepare-npm-package.js b/scripts/prepare-npm-package.js index 714e4691981..13c0ea08730 100644 --- a/scripts/prepare-npm-package.js +++ b/scripts/prepare-npm-package.js @@ -52,25 +52,34 @@ try { // then generate an additional "nested" package.json for typescript resolution that // doesn't use the exports property in package.json. if (process.env.ALIAS_PACKAGE_NAME) { - const aliasName = process.env.ALIAS_PACKAGE_NAME; + const aliasNames = process.env.ALIAS_PACKAGE_NAME.split(','); + + const additionalExports = aliasNames.reduce((acc, alias) => { + acc[`./${alias}`] = { + import: { + types: typesIndex.replace('index', alias), + default: esmIndex.replace('index', alias), + }, + require: { + types: typesIndex.replace('index', alias), + default: cjsIndex.replace('index', alias), + }, + }; + return acc; + }, {}); + pkgJson.update({ exports: { ...pkgJson.content.exports, - [`./${aliasName}`]: { - import: { - types: typesIndex.replace('index', aliasName), - default: esmIndex.replace('index', aliasName), - }, - require: { - types: typesIndex.replace('index', aliasName), - default: cjsIndex.replace('index', aliasName), - }, - }, + ...additionalExports, }, - files: [...pkgJson.content.files, aliasName], + files: [...pkgJson.content.files, ...aliasNames], }); await pkgJson.save(); - await createAliasPackageJsonFiles(pkgJson.content, aliasName); + + for await (const aliasName of aliasNames) { + await createAliasPackageJsonFiles(pkgJson.content, aliasName); + } } } catch (e) { console.error(e);