Skip to content

Commit

Permalink
refactor(switch): convert to esm
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Drop cjs; esm only; all in on tree shaking
BREAKING CHANGE: Remove file imports (eg, packageName/react)
  • Loading branch information
jaketrent committed Mar 30, 2021
1 parent 672db05 commit 0893d2b
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 26 deletions.
Expand Up @@ -4,5 +4,12 @@ module.exports = {
typescript: {
check: true,
reactDocgen: 'react-docgen-typescript'
},
webpackFinal: async (config, { configType }) => {
config.module.rules.push({
test: /\.mjs$/,
type: 'javascript/auto'
})
return config
}
}
1 change: 1 addition & 0 deletions packages/switch/.storybook-storyshots/preview.js
@@ -0,0 +1 @@
import '@pluralsight/ps-design-system-normalize'
15 changes: 15 additions & 0 deletions packages/switch/.storybook/main.cjs
@@ -0,0 +1,15 @@
module.exports = {
addons: ['@pluralsight/ps-design-system-storybook-preset'],
stories: ['../src/**/*.story.@(js|ts|tsx)'],
typescript: {
check: true,
reactDocgen: 'react-docgen-typescript'
},
webpackFinal: async (config, { configType }) => {
config.module.rules.push({
test: /\.mjs$/,
type: 'javascript/auto'
})
return config
}
}
1 change: 0 additions & 1 deletion packages/switch/css.js

This file was deleted.

14 changes: 10 additions & 4 deletions packages/switch/jest.config.js
@@ -1,9 +1,15 @@
const path = require('path')
import * as path from 'path'
import readPkg from 'read-pkg-up'
import { fileURLToPath } from 'url'

const baseConfig = require('../../jest/base.config.js')
const { name } = require('./package.json')
import baseConfig from '../../jest/base.config.js'

module.exports = {
const {
packageJson: { name }
} = readPkg.sync()
const __dirname = path.dirname(fileURLToPath(import.meta.url))

export default {
...baseConfig,
displayName: name,
name: name,
Expand Down
15 changes: 9 additions & 6 deletions packages/switch/package.json
Expand Up @@ -6,19 +6,22 @@
"repository": "pluralsight/design-system",
"author": "jaketrent",
"keywords": [],
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"main": "dist/esm/index.mjs",
"module": "dist/esm/index.mjs",
"scripts": {
"build": "run-s build:cjs build:esm build:css",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --target es5 --outDir dist/cjs",
"build:css": "build-css --useGlamor -i dist/cjs/css/index.js",
"build:esm": "tsc --project tsconfig.build.json --module es2015 --target es5 --outDir dist/esm",
"build": "run-s build:esm build:css",
"build:css": "build-css --useGlamor -i dist/esm/css/index.mjs",
"build:esm": "run-s compile:esm rewrite:esm",
"build:watch": "yarn build:esm --watch",
"compile:esm": "tsc --project tsconfig.build.json --module es2015 --target es5 --outDir dist/esm",
"rewrite:esm": "tsc-esm --project tsconfig.build.json",
"storybook": "start-storybook -p 6006",
"test": "tsc --noEmit --project ./tsconfig.json && jest",
"test:watch": "yarn test --watchAll"
},
"sideEffects": false,
"style": "dist/index.css",
"type": "module",
"types": "dist/esm/index.d.ts",
"dependencies": {
"@pluralsight/ps-design-system-core": "^6.9.3",
Expand Down
1 change: 0 additions & 1 deletion packages/switch/react.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/switch/src/css/index.ts
Expand Up @@ -15,7 +15,7 @@ import {
names as themeNames
} from '@pluralsight/ps-design-system-theme'

import * as vars from '../vars'
import * as vars from '../vars/index'

export default {
'.psds-switch': {
Expand Down
6 changes: 3 additions & 3 deletions packages/switch/src/index.ts
@@ -1,3 +1,3 @@
export { default } from './react'
export * from './vars'
export { default as css } from './css'
export { default } from './react/index'
export * from './vars/index'
export { default as css } from './css/index'
3 changes: 1 addition & 2 deletions packages/switch/src/react/__specs__/index.spec.tsx
@@ -1,9 +1,8 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */

import { fireEvent, render } from '@testing-library/react'
import React from 'react'

import Switch from '..'
import Switch from '../index'

describe('Switch', () => {
it('forwards refs', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/switch/src/react/__specs__/storyshots.spec.ts
Expand Up @@ -6,7 +6,7 @@ import initStoryshots, {
const createNodeMock = () => document.createElement('div')

initStoryshots({
configPath: path.resolve(__dirname, '../../../.storybook'),
configPath: path.resolve(__dirname, '../../../.storybook-storyshots'),
framework: 'react',
test: snapshotWithOptions({ createNodeMock })
})
2 changes: 1 addition & 1 deletion packages/switch/src/react/__stories__/index.story.tsx
@@ -1,7 +1,7 @@
import React from 'react'
import { storiesOf } from '@storybook/react'

import Switch from '..'
import Switch from '../index'

const sizeStory = storiesOf('size', module)
Object.values(Switch.sizes).forEach(size =>
Expand Down
9 changes: 4 additions & 5 deletions packages/switch/src/react/index.tsx
@@ -1,6 +1,3 @@
import { compose, css } from 'glamor'
import React from 'react'

import Halo from '@pluralsight/ps-design-system-halo'
import {
useTheme,
Expand All @@ -13,9 +10,11 @@ import {
HTMLPropsFor,
RefFor
} from '@pluralsight/ps-design-system-util'
import { compose, css } from 'glamor'
import React from 'react'

import stylesheet from '../css'
import * as vars from '../vars'
import stylesheet from '../css/index'
import * as vars from '../vars/index'

const styles = {
switch: (disabled: boolean, labelAlign: ValueOf<typeof vars.labelAligns>) =>
Expand Down
1 change: 0 additions & 1 deletion packages/switch/vars.js

This file was deleted.

0 comments on commit 0893d2b

Please sign in to comment.