diff --git a/packages/dnb-eufemia/jest.config.js b/packages/dnb-eufemia/jest.config.js index d90de262ac4..fe51b1405e1 100644 --- a/packages/dnb-eufemia/jest.config.js +++ b/packages/dnb-eufemia/jest.config.js @@ -4,6 +4,7 @@ const config = { testRegex: '(/__tests__/\\.js|(\\.|/)(test|spec))\\.(js|jsx|ts)?$', modulePathIgnorePatterns: [ 'not_in_use', + '/scripts/release/__tests__/postbuild.test*', '/build/', '/assets/', '/stories/', diff --git a/packages/dnb-eufemia/package.json b/packages/dnb-eufemia/package.json index a0e7db53a82..dc2da36017f 100644 --- a/packages/dnb-eufemia/package.json +++ b/packages/dnb-eufemia/package.json @@ -21,7 +21,7 @@ "audit:ci:yarn-outdated": "babel-node ./scripts/prepub/audit/toOpt && audit-ci --config ./audit-ci.json --package-manager=yarn --report-type full && babel-node ./scripts/prepub/audit/toDev", "build": "yarn build:prebuild && yarn build:esm && yarn build:copy", "prebuild:ci": "yarn build", - "postbuild:ci": "yarn build:types && yarn build:cjs && yarn build:es && yarn build:umd && yarn build:esm && yarn build:copy && yarn prettier:other && echo \"Can be enabled in future -> yarn build:resources\"", + "postbuild:ci": "./scripts/release/postbuild.sh", "build:cjs": "./scripts/release/babel-cjs.sh", "build:clean": "rm -rf build/**", "build:copy": "./scripts/release/copy-build-artifacts.sh", @@ -63,6 +63,7 @@ "skeleton:font": "nodemon --exec 'babel-node ./scripts/tools/createSkeletonFont.js'", "start": "yarn workspace dnb-eufemia-sandbox start", "test": "jest", + "test:build": "jest --ci --rootDir ./scripts/release", "test:ci": "jest --ci", "test:screenshots": "jest --config=./jest.config.screenshots.js --forceExit --detectOpenHandles", "test:screenshots:ci": "jest --config=./jest.config.screenshots.js --ci --forceExit --detectOpenHandles", diff --git a/packages/dnb-eufemia/scripts/release/__tests__/postbuild.test.js b/packages/dnb-eufemia/scripts/release/__tests__/postbuild.test.js new file mode 100644 index 00000000000..fd9f4e915b6 --- /dev/null +++ b/packages/dnb-eufemia/scripts/release/__tests__/postbuild.test.js @@ -0,0 +1,120 @@ +/** + * Test postbuild stage + * check if important files do exists + * + */ + +import fs from 'fs-extra' +import path from 'path' + +const buildStages = ['es', 'esm', 'cjs'] + +describe('type definitions', () => { + it.each(buildStages)('has d.ts index file on stage %s', (stage) => { + const file = path.resolve(`./build/${stage}/index.d.ts`) + const exists = fs.existsSync(file) + expect(exists).toBe(true) + }) + + it.each(buildStages)( + 'has correct Modal type definitions on stage %s', + (stage) => { + expect( + fs.existsSync( + path.resolve(`./build/${stage}/components/Modal.d.ts`) + ) + ).toBe(true) + + // To ensure babel did not compile the d.ts file + expect( + fs.readFileSync( + path.resolve(`./build/${stage}/components/modal/Modal.d.ts`), + 'utf-8' + ) + ).toMatch(/export interface/g) + } + ) +}) + +describe('babel build', () => { + it.each(buildStages)('has correctly compiled on stage %s', (stage) => { + expect( + fs.existsSync(path.resolve(`./build/${stage}/components/Modal.js`)) + ).toBe(true) + + switch (stage) { + case 'cjs': + { + { + const content = fs.readFileSync( + path.resolve(`./build/${stage}/index.js`), + 'utf-8' + ) + expect(content).toContain( + 'Object.defineProperty(exports, "__esModule", {' + ) + expect(content).toContain(`var _default = {};`) + + // Has extra cjs package + expect( + fs.existsSync(path.resolve(`./build/${stage}/package.json`)) + ).toBe(true) + } + + { + const content = fs.readFileSync( + path.resolve(`./build/${stage}/components/modal/Modal.js`), + 'utf-8' + ) + expect(content).toContain('var Modal = function') + expect(content).toMatch(/^"use strict";/g) + } + } + break + + case 'esm': + { + { + const content = fs.readFileSync( + path.resolve(`./build/${stage}/index.js`), + 'utf-8' + ) + expect(content).toContain('export default {};') + } + + const content = fs.readFileSync( + path.resolve(`./build/${stage}/components/modal/Modal.js`), + 'utf-8' + ) + expect(content).toContain('export { Modal as default };') + expect(content).toContain('core-js/modules/es') + expect(content).toContain( + 'import _extends from "@babel/runtime/helpers/esm/extends";' + ) + } + break + + case 'es': + { + { + const content = fs.readFileSync( + path.resolve(`./build/${stage}/index.js`), + 'utf-8' + ) + expect(content).toContain('export default {};') + } + + const content = fs.readFileSync( + path.resolve(`./build/${stage}/components/modal/Modal.js`), + 'utf-8' + ) + expect(content).toMatch(/export default class Modal extends/g) + expect(content).not.toContain('core-js/modules/es') + expect(content).toContain( + 'import _extends from "@babel/runtime/helpers/esm/extends";' + ) + } + break + } + }) +}) diff --git a/packages/dnb-eufemia/scripts/release/babel-cjs.sh b/packages/dnb-eufemia/scripts/release/babel-cjs.sh index b3d2a7fd3c7..9a9d7d91447 100755 --- a/packages/dnb-eufemia/scripts/release/babel-cjs.sh +++ b/packages/dnb-eufemia/scripts/release/babel-cjs.sh @@ -16,6 +16,10 @@ babel ./src \ echo 'Building cjs done!' -echo 'Copy .d.ts files ...' +echo 'Copy .d.ts files to cjs ...' OUT_DIR=./build/cjs babel-node ./scripts/release/copyTypeScriptDefinitionFiles.js + +echo 'Copy extra cjs package.json ...' + +cp ./src/cjs/package.json ./build/cjs/package.json diff --git a/packages/dnb-eufemia/scripts/release/babel-es.sh b/packages/dnb-eufemia/scripts/release/babel-es.sh index 018d1643579..49eb3ed5f49 100755 --- a/packages/dnb-eufemia/scripts/release/babel-es.sh +++ b/packages/dnb-eufemia/scripts/release/babel-es.sh @@ -16,6 +16,6 @@ babel ./src \ echo 'Building es done!' -echo 'Copy .d.ts files ...' +echo 'Copy .d.ts files to es ...' OUT_DIR=./build/es babel-node ./scripts/release/copyTypeScriptDefinitionFiles.js diff --git a/packages/dnb-eufemia/scripts/release/babel-esm.sh b/packages/dnb-eufemia/scripts/release/babel-esm.sh index 6125261110b..46557834922 100755 --- a/packages/dnb-eufemia/scripts/release/babel-esm.sh +++ b/packages/dnb-eufemia/scripts/release/babel-esm.sh @@ -16,6 +16,6 @@ babel ./src \ echo 'Building esm done!' -echo 'Copy .d.ts files ...' +echo 'Copy .d.ts files to esm ...' OUT_DIR=./build/esm babel-node ./scripts/release/copyTypeScriptDefinitionFiles.js diff --git a/packages/dnb-eufemia/scripts/release/postbuild.sh b/packages/dnb-eufemia/scripts/release/postbuild.sh new file mode 100755 index 00000000000..e4134fb1e49 --- /dev/null +++ b/packages/dnb-eufemia/scripts/release/postbuild.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +echo 'Postbuild started ...' + +yarn build:types +yarn build:cjs +yarn build:es +yarn build:esm +yarn build:umd +echo 'Can be enabled in future if needed -> yarn build:resources' +yarn build:copy +yarn prettier:other +yarn test:build + +echo 'Postbuild done!'