Skip to content

Commit 3cf811e

Browse files
committed
correctly configure ES Module for packages/icons
1 parent dbf011d commit 3cf811e

File tree

8 files changed

+39
-8
lines changed

8 files changed

+39
-8
lines changed

packages/icons/.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
**/dist
22
index.js
3+
index.mjs
34
**/*.d.ts
5+
**/*.d.mts
46
**/package-lock.json
57
**/tsconfig.json
68
**/cypress/fixtures

packages/icons/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
**/dist
22
index.js
3-
index.d.ts
3+
index.mjs
4+
index.d.ts
5+
index.d.mts

packages/icons/index.mts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import path from 'path'
2+
3+
const dist = [import.meta.dirname, 'dist']
4+
5+
function distPath (...args: string[]) {
6+
return path.join.apply(path, dist.concat([...args]))
7+
}
8+
9+
export const getPathToFavicon = (filename: string) => {
10+
return distPath('favicon', filename)
11+
}
12+
13+
export const getPathToIcon = (filename: string) => {
14+
return distPath('icons', filename)
15+
}
16+
17+
export const getPathToLogo = (filename: string) => {
18+
return distPath('logo', filename)
19+
}

packages/icons/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
],
3232
"types": "index.d.ts",
3333
"license": "MIT",
34+
"module": "index.mjs",
3435
"nx": {}
3536
}

packages/icons/test/icons.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import { describe, it, expect } from 'vitest'
2-
import * as icons from '../index'
2+
import * as iconsESM from '../index.mjs'
3+
import * as iconsCjs from '../index.js'
34

45
const cwd = process.cwd()
56

67
describe('Cypress Icons', function () {
78
it('returns path to favicon', function () {
8-
expect(icons.getPathToFavicon('favicon-red.ico')).toEqual(`${cwd }/dist/favicon/favicon-red.ico`)
9+
expect(iconsESM.getPathToFavicon('favicon-red.ico')).toEqual(`${cwd }/dist/favicon/favicon-red.ico`)
10+
expect(iconsCjs.getPathToFavicon('favicon-red.ico')).toEqual(`${cwd }/dist/favicon/favicon-red.ico`)
911
})
1012

1113
it('returns path to icon', function () {
12-
expect(icons.getPathToIcon('cypress.icns')).toEqual(`${cwd }/dist/icons/cypress.icns`)
14+
expect(iconsESM.getPathToIcon('cypress.icns')).toEqual(`${cwd }/dist/icons/cypress.icns`)
15+
expect(iconsCjs.getPathToIcon('cypress.icns')).toEqual(`${cwd }/dist/icons/cypress.icns`)
1316
})
1417

1518
it('returns path to logo', function () {
16-
expect(icons.getPathToLogo('cypress-bw.png')).toEqual(`${cwd }/dist/logo/cypress-bw.png`)
19+
expect(iconsESM.getPathToLogo('cypress-bw.png')).toEqual(`${cwd }/dist/logo/cypress-bw.png`)
20+
expect(iconsCjs.getPathToLogo('cypress-bw.png')).toEqual(`${cwd }/dist/logo/cypress-bw.png`)
1721
})
1822
})

packages/icons/tsconfig.base.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"include": [
3-
"index.ts"
4-
],
52
"compilerOptions": {
63
"allowJs": false,
74
"noImplicitAny": true,

packages/icons/tsconfig.cjs.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"extends": "./tsconfig.base.json",
3+
"include": [
4+
"index.ts"
5+
],
36
"compilerOptions": {
47
"target": "ES2022",
58
"module": "CommonJS",

packages/icons/tsconfig.esm.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"extends": "./tsconfig.base.json",
3+
"include": [
4+
"index.mts"
5+
],
36
"compilerOptions": {
47
"target": "ES2022",
58
"module": "ES2022",

0 commit comments

Comments
 (0)