@helsenorge/library-build 32.0.1 → 33.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=build.d.ts.map
package/build.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":""}
package/build.js ADDED
@@ -0,0 +1,24 @@
1
+ import { existsSync, mkdirSync } from 'fs';
2
+ import esbuild from 'esbuild';
3
+ import yargs from 'yargs';
4
+ import { hideBin } from 'yargs/helpers';
5
+ (async () => {
6
+ const { entry, outDir, tsconfig } = await yargs(hideBin(process.argv))
7
+ .options({
8
+ entry: { type: 'string', default: 'src/__devonly__/index.tsx' },
9
+ outDir: { type: 'string', default: 'dist' },
10
+ tsconfig: { type: 'string', default: 'tsconfig.json' },
11
+ })
12
+ .parse();
13
+ if (!existsSync(outDir)) {
14
+ mkdirSync(outDir);
15
+ }
16
+ await esbuild.build({
17
+ format: 'esm',
18
+ entryPoints: [entry],
19
+ outdir: outDir,
20
+ tsconfig: tsconfig,
21
+ bundle: true,
22
+ external: ['*'],
23
+ });
24
+ })();
@@ -23,7 +23,7 @@
23
23
  /* library-build specific options */
24
24
  "declaration": true,
25
25
  "declarationMap": true,
26
-
27
- "esModuleInterop": true
26
+ "esModuleInterop": true,
27
+ "types": ["vitest/globals", "@testing-library/jest-dom"]
28
28
  }
29
29
  }
package/copy.js CHANGED
@@ -19,9 +19,11 @@ const { name: packageName, publishConfig: { directory: outputDirectory }, } = re
19
19
  const outputPath = path.resolve(process.cwd(), outputDirectory);
20
20
  const newPackageJson = path.resolve(outputPath, 'package.json');
21
21
  Promise.all([
22
- new Promise((resolve, reject) => copyfiles([...root, outputPath], e => (e ? reject(e) : resolve()))),
23
- new Promise((resolve, reject) => copyfiles([...include, outputPath], { up: 1 }, e => (e ? reject(e) : resolve()))),
24
- new Promise((resolve, reject) => copyfiles([...utils, path.resolve(outputPath, 'utils')], { up: true }, e => (e ? reject(e) : resolve()))),
22
+ new Promise((resolve, reject) => root.length > 0 ? copyfiles([...root, outputPath], { error: true }, e => (e ? reject(e) : resolve())) : resolve()),
23
+ new Promise((resolve, reject) => include.length > 0 ? copyfiles([...include, outputPath], { up: 1, error: true }, e => (e ? reject(e) : resolve())) : resolve()),
24
+ new Promise((resolve, reject) => utils.length > 0
25
+ ? copyfiles([...utils, path.resolve(outputPath, 'utils')], { up: true, error: true }, e => (e ? reject(e) : resolve()))
26
+ : resolve()),
25
27
  ])
26
- .then(() => (rm ? rimraf(rm) : Promise.resolve(true)))
28
+ .then(() => (rm ? rimraf(rm, { glob: true }) : Promise.resolve(true)))
27
29
  .then(() => createPackageJsonFile(packageName, originalPackageJson, newPackageJson));
package/index.html CHANGED
@@ -31,6 +31,6 @@
31
31
 
32
32
  <!-- IMPORT header-footer script -->
33
33
  <script type="module" src="https://static-hn-mas-01.int-hn.nhn.no/header-footer/static/js/header-footer/header-footer.js"></script>
34
- <script src="index.js"></script>
34
+ <script type="module" src="index.js"></script>
35
35
  </body>
36
36
  </html>
@@ -1,14 +1,15 @@
1
1
  #! /usr/bin/env node
2
+ /* eslint-disable no-console */
2
3
  import { createRequire } from 'node:module';
3
4
  const require = createRequire(import.meta.url);
4
5
  const sync = require('cross-spawn').sync;
5
6
  const args = process.argv.slice(2);
6
- const scriptIndex = args.findIndex(x => x === 'start' || x === 'test' || x === 'copy');
7
+ const scriptIndex = args.findIndex(x => x === 'start' || x === 'build' || x === 'copy');
7
8
  const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
8
9
  const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
9
10
  switch (script) {
10
11
  case 'start':
11
- case 'test':
12
+ case 'build':
12
13
  case 'copy': {
13
14
  const result = sync('node', nodeArgs.concat(require.resolve('./' + script)).concat(args.slice(scriptIndex + 1)), {
14
15
  stdio: 'inherit',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@helsenorge/library-build",
3
3
  "author": "Norsk helsenett SF",
4
- "version": "32.0.1",
4
+ "version": "33.1.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "repository": {
@@ -13,39 +13,30 @@
13
13
  },
14
14
  "license": "MIT",
15
15
  "peerDependencies": {
16
- "react": "^17.0.0 || ^18.0.0",
17
- "react-dom": "^17.0.0 || ^18.0.0"
16
+ "react": "^18.0.0",
17
+ "react-dom": "^18.0.0"
18
18
  },
19
19
  "dependencies": {
20
- "@babel/core": "^7.25.2",
21
- "@helsenorge/eslint-config": "^32.0.0",
22
- "@testing-library/jest-dom": "^6.4.8",
23
- "@testing-library/react": "^16.0.0",
20
+ "@helsenorge/eslint-config": "^33.0.0",
21
+ "@testing-library/jest-dom": "^6.6.3",
22
+ "@testing-library/react": "^16.0.1",
24
23
  "@testing-library/user-event": "^14.5.2",
25
24
  "@types/copyfiles": "^2.4.4",
26
- "@types/react": "^18.3.3",
27
- "@types/react-dom": "^18.3.0",
28
- "@vitest/coverage-v8": "^1.6.0",
29
- "babel-jest": "^29.7.0",
30
- "babel-preset-react-app": "^10.0.1",
25
+ "@types/react": "^18.3.12",
26
+ "@types/react-dom": "^18.3.1",
27
+ "@vitest/coverage-v8": "^2.1.4",
31
28
  "copyfiles": "^2.4.1",
32
- "crlf": "^1.1.1",
33
29
  "cross-spawn": "^7.0.3",
34
30
  "esbuild": "^0.21.5",
35
31
  "esbuild-sass-plugin": "^3.3.1",
36
- "identity-obj-proxy": "^3.0.0",
37
- "jest": "^29.7.0",
38
- "jest-environment-jsdom": "^29.7.0",
39
- "jest-junit-reporter": "^1.1.0",
40
- "jest-resolve": "^29.7.0",
41
- "postcss": "^8.4.41",
32
+ "postcss": "^8.4.47",
42
33
  "postcss-modules": "^6.0.0",
43
- "rimraf": "^5.0.10",
44
- "tslib": "^2.6.3",
34
+ "rimraf": "^6.0.1",
45
35
  "typed-scss-modules": "^8.0.1",
46
- "typescript": "^5.5.4",
47
- "vitest": "^1.6.0",
48
- "whatwg-fetch": "^3.6.20"
36
+ "typescript": "~5.5.4",
37
+ "vitest": "^2.1.4",
38
+ "whatwg-fetch": "^3.6.20",
39
+ "yargs": "^17.7.2"
49
40
  },
50
41
  "publishConfig": {
51
42
  "access": "public"
@@ -1,4 +1,4 @@
1
- import '@testing-library/jest-dom';
1
+ import '@testing-library/jest-dom/vitest';
2
2
  import 'whatwg-fetch';
3
3
  declare global {
4
4
  interface Window {
@@ -1 +1 @@
1
- {"version":3,"file":"setupTests.vite.d.ts","sourceRoot":"","sources":["../src/setupTests.vite.ts"],"names":[],"mappings":"AACA,OAAO,2BAA2B,CAAC;AACnC,OAAO,cAAc,CAAC;AAEtB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC7B;CACF"}
1
+ {"version":3,"file":"setupTests.vite.d.ts","sourceRoot":"","sources":["../src/setupTests.vite.ts"],"names":[],"mappings":"AACA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,cAAc,CAAC;AAEtB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC7B;CACF"}
@@ -1,5 +1,5 @@
1
1
  import { vi } from 'vitest';
2
- import '@testing-library/jest-dom';
2
+ import '@testing-library/jest-dom/vitest';
3
3
  import 'whatwg-fetch';
4
4
  window.HN = {
5
5
  Page: {},
@@ -8,54 +8,28 @@ window.HN = {
8
8
  Commands: {},
9
9
  PortalCommands: {},
10
10
  };
11
- const mockWindowMatchMedia = vi.fn().mockImplementation(() => ({
11
+ const MatchMediaMock = vi.fn(() => ({
12
12
  matches: true,
13
+ addListener: vi.fn(),
13
14
  addEventListener: vi.fn(),
14
15
  removeEventListener: vi.fn(),
15
16
  }));
16
- Object.defineProperty(window, 'matchMedia', {
17
- writable: true,
18
- value: mockWindowMatchMedia,
19
- });
20
- class IntersectionObserver {
21
- observe() {
22
- // do nothing
23
- }
24
- unobserve() {
25
- // do nothing
26
- }
27
- disconnect() {
28
- // do nothing
29
- }
30
- }
31
- Object.defineProperty(window, 'IntersectionObserver', {
32
- writable: true,
33
- value: IntersectionObserver,
34
- });
35
- class ResizeObserver {
36
- observe() {
37
- // do nothing
38
- }
39
- unobserve() {
40
- // do nothing
41
- }
42
- disconnect() {
43
- // do nothing
44
- }
45
- }
46
- Object.defineProperty(window, 'ResizeObserver', {
47
- writable: true,
48
- value: ResizeObserver,
49
- });
50
- class MutationObserver {
51
- observe() {
52
- // do nothing
53
- }
54
- disconnect() {
55
- // do nothing
56
- }
57
- }
58
- Object.defineProperty(window, 'MutationObserver', {
59
- writable: true,
60
- value: MutationObserver,
61
- });
17
+ vi.stubGlobal('matchMedia', MatchMediaMock);
18
+ const IntersectionObserverMock = vi.fn(() => ({
19
+ observe: vi.fn(),
20
+ unobserve: vi.fn(),
21
+ disconnect: vi.fn(),
22
+ }));
23
+ vi.stubGlobal('IntersectionObserver', IntersectionObserverMock);
24
+ const ResizeObserverMock = vi.fn(() => ({
25
+ observe: vi.fn(),
26
+ unobserve: vi.fn(),
27
+ disconnect: vi.fn(),
28
+ }));
29
+ vi.stubGlobal('ResizeObserver', ResizeObserverMock);
30
+ const MutationObserverMock = vi.fn(() => ({
31
+ observe: vi.fn(),
32
+ disconnect: vi.fn(),
33
+ }));
34
+ vi.stubGlobal('MutationObserver', MutationObserverMock);
35
+ window.HTMLElement.prototype.scrollIntoView = vi.fn();
package/start.js CHANGED
@@ -19,12 +19,14 @@ const __dirname = path.dirname(__filename);
19
19
  }
20
20
  copyFileSync(__dirname + '/index.html', outDir + '/index.html');
21
21
  const context = await esbuild.context({
22
+ format: 'esm',
22
23
  logLevel: 'debug',
23
24
  entryPoints: [entry],
24
25
  outdir: outDir,
25
26
  bundle: true,
26
27
  define: {
27
28
  global: 'window',
29
+ 'import.meta.env': '{}',
28
30
  },
29
31
  loader: {
30
32
  '.svg': 'dataurl',
package/vitest.config.js CHANGED
@@ -26,7 +26,7 @@ export const getConfig = () => {
26
26
  },
27
27
  server: {
28
28
  deps: {
29
- inline: ['@helsenorge/designsystem-react', '@portabletext/react'],
29
+ inline: ['@helsenorge/designsystem-react', '@helsenorge/datepicker', '@helsenorge/lightbox', '@portabletext/react'],
30
30
  },
31
31
  },
32
32
  },
@@ -1,14 +0,0 @@
1
- const parentBabelConfig = {
2
- presets: [
3
- ['@babel/preset-env', { targets: { node: 'current' } }],
4
- ['@babel/preset-react', { typescript: true, runtime: 'automatic' }],
5
- ['@babel/preset-typescript', { allExtensions: true, isTSX: true }],
6
- ],
7
- plugins: [
8
- '@babel/plugin-syntax-dynamic-import',
9
- ['@babel/plugin-proposal-class-properties', { loose: true }],
10
- '@babel/plugin-transform-object-rest-spread',
11
- ],
12
- };
13
-
14
- module.exports = parentBabelConfig;
package/jest.config.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { Config } from 'jest';
2
- declare const config: Config;
3
- export default config;
4
- //# sourceMappingURL=jest.config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jest.config.d.ts","sourceRoot":"","sources":["../src/jest.config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAenC,QAAA,MAAM,MAAM,EAAE,MAsCb,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/jest.config.js DELETED
@@ -1,52 +0,0 @@
1
- import { createRequire } from 'node:module';
2
- const require = createRequire(import.meta.url);
3
- /* Legger til babel-jest + esm og babel-jest igjen uner 'transform' for å kunne håndtere esm import/exports */
4
- /* Viktig å ha @helsenorge pakker under transformIgnorePatterns fordi de eksporteres i rå esm */
5
- let individualConfig;
6
- const rootDir = process.cwd();
7
- try {
8
- individualConfig = require(rootDir + '/jest.config.cjs');
9
- }
10
- catch (ex) {
11
- console.log('Benytter delt jest.config.js-fil');
12
- }
13
- const config = {
14
- rootDir,
15
- verbose: true,
16
- setupFilesAfterEnv: ['<rootDir>/node_modules/@helsenorge/library-build/setupTests.js'],
17
- coverageProvider: 'v8',
18
- testEnvironment: 'jest-environment-jsdom',
19
- testEnvironmentOptions: {
20
- url: 'http://tjenester.helsenorge.utvikling',
21
- },
22
- transform: {
23
- '^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
24
- },
25
- transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\](?!(@helsenorge)[/\\\\])', '^.+\\.module\\.(css|sass|scss|scss.d.ts)$'],
26
- coverageReporters: ['cobertura', 'lcov', 'json'],
27
- collectCoverage: true,
28
- collectCoverageFrom: [
29
- '**/*.ts',
30
- '**/*.tsx',
31
- '!**/node_modules/**',
32
- '!**/lib/**',
33
- '!**/dist/**',
34
- '!**/__devonly__/**',
35
- '!**/scripts/**',
36
- '!**/types/**',
37
- '!**/constants/*.ts',
38
- '!**/*types.ts',
39
- ],
40
- moduleNameMapper: {
41
- '\\.(css|scss)$': 'identity-obj-proxy',
42
- },
43
- moduleDirectories: ['node_modules', 'src'],
44
- // Unngå warning om jest-haste-map: Haste module naming collision
45
- modulePathIgnorePatterns: ['lib'],
46
- moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
47
- coveragePathIgnorePatterns: ['^.+\\.module\\.(css|sass|scss|scss.d.ts)$'],
48
- testResultsProcessor: 'jest-junit-reporter',
49
- cacheDirectory: '<rootDir>/.jest-cache',
50
- ...individualConfig,
51
- };
52
- export default config;
package/setupTests.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- import 'whatwg-fetch';
3
- declare global {
4
- interface Window {
5
- HN: Record<string, unknown>;
6
- }
7
- }
8
- //# sourceMappingURL=setupTests.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setupTests.d.ts","sourceRoot":"","sources":["../src/setupTests.ts"],"names":[],"mappings":"AAIA,OAAO,2BAA2B,CAAC;AACnC,OAAO,cAAc,CAAC;AAEtB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC7B;CACF"}
package/setupTests.js DELETED
@@ -1,64 +0,0 @@
1
- // jest-dom adds custom jest matchers for asserting on DOM nodes.
2
- // allows you to do things like:
3
- // expect(element).toHaveTextContent(/react/i)
4
- // learn more: https://github.com/testing-library/jest-dom
5
- import '@testing-library/jest-dom';
6
- import 'whatwg-fetch';
7
- window.HN = {
8
- Page: {},
9
- Rest: {},
10
- User: {},
11
- Commands: {},
12
- PortalCommands: {},
13
- };
14
- const mockWindowMatchMedia = jest.fn().mockImplementation(() => ({
15
- matches: true,
16
- addEventListener: jest.fn(),
17
- removeEventListener: jest.fn(),
18
- }));
19
- Object.defineProperty(window, 'matchMedia', {
20
- writable: true,
21
- value: mockWindowMatchMedia,
22
- });
23
- class IntersectionObserver {
24
- observe() {
25
- // do nothing
26
- }
27
- unobserve() {
28
- // do nothing
29
- }
30
- disconnect() {
31
- // do nothing
32
- }
33
- }
34
- Object.defineProperty(window, 'IntersectionObserver', {
35
- writable: true,
36
- value: IntersectionObserver,
37
- });
38
- class ResizeObserver {
39
- observe() {
40
- // do nothing
41
- }
42
- unobserve() {
43
- // do nothing
44
- }
45
- disconnect() {
46
- // do nothing
47
- }
48
- }
49
- Object.defineProperty(window, 'ResizeObserver', {
50
- writable: true,
51
- value: ResizeObserver,
52
- });
53
- class MutationObserver {
54
- observe() {
55
- // do nothing
56
- }
57
- disconnect() {
58
- // do nothing
59
- }
60
- }
61
- Object.defineProperty(window, 'MutationObserver', {
62
- writable: true,
63
- value: MutationObserver,
64
- });
package/test.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=test.d.ts.map
package/test.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":""}
package/test.js DELETED
@@ -1,22 +0,0 @@
1
- import { createRequire } from 'node:module';
2
- const require = createRequire(import.meta.url);
3
- // Do this as the first thing so that any code reading it knows the right env.
4
- process.env.BABEL_ENV = 'test';
5
- process.env.NODE_ENV = 'test';
6
- process.env.PUBLIC_URL = '';
7
- process.env.TZ = process.env.TZ ?? 'Europe/Oslo';
8
- // Makes the script crash on unhandled rejections instead of silently
9
- // ignoring them. In the future, promise rejections that are not handled will
10
- // terminate the Node.js process with a non-zero exit code.
11
- process.on('unhandledRejection', err => {
12
- throw err;
13
- });
14
- const jestInstance = require('jest');
15
- const argv = process.argv.slice(2);
16
- // Always set config
17
- argv.push('--coverage');
18
- argv.push('--verbose');
19
- argv.push('--no-cache');
20
- argv.push('--config=node_modules/@helsenorge/library-build/jest.config.js');
21
- console.log('Du kjører jest med følgende arguments: ', argv);
22
- jestInstance.run(argv);