Skip to content

Commit

Permalink
add typescript definition
Browse files Browse the repository at this point in the history
  • Loading branch information
le0pard committed Aug 10, 2023
1 parent 531f6fc commit a9185b7
Show file tree
Hide file tree
Showing 8 changed files with 1,539 additions and 772 deletions.
34 changes: 18 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
"packages/*"
],
"scripts": {
"build": "rollup --bundleConfigAsCjs -c --environment BUILD:production",
"build": "rollup --bundleConfigAsCjs -c && tsc",
"dev": "rollup --bundleConfigAsCjs -c -w",
"lint": "eslint packages/**/src/*.js shared/**/*.js *.config.js",
"lint": "pnpify run prettier --check packages/**/src/*.js && eslint packages/**/src/*.js shared/**/*.js *.config.js",
"test": "jest --config jest.config.js",
"test:watch": "jest --config jest.config.js --watch"
"test:watch": "jest --config jest.config.js --watch",
"format": "pnpify run prettier --write packages/**/src/*.js"
},
"author": "Alexey Vasiliev",
"license": "MIT",
Expand All @@ -27,23 +28,24 @@
},
"homepage": "https://github.com/le0pard/cable-shared-worker#readme",
"devDependencies": {
"@babel/core": "^7.22.8",
"@babel/eslint-parser": "^7.22.7",
"@babel/preset-env": "^7.22.7",
"@babel/core": "^7.22.10",
"@babel/eslint-parser": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^25.0.2",
"@rollup/plugin-commonjs": "^25.0.3",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-terser": "^0.4.3",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-node": "^0.3.7",
"eslint-plugin-import": "^2.27.5",
"jest": "^29.6.1",
"jest-environment-jsdom": "^29.6.1",
"@yarnpkg/pnpify": "^4.0.0-rc.48",
"eslint": "^8.46.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-node": "^0.3.9",
"eslint-plugin-import": "^2.28.0",
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"jsdom": "^22.1.0",
"prettier": "^3.0.0",
"rollup": "^3.26.2"
"prettier": "^3.0.1",
"rollup": "^3.28.0",
"typescript": "^5.1.6"
},
"packageManager": "yarn@3.6.0"
}
1 change: 0 additions & 1 deletion packages/web/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# production
dist
lib
15 changes: 8 additions & 7 deletions packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cable-shared-worker/web",
"version": "0.3.2",
"version": "0.4.0",
"description": "ActionCable and AnyCable Shared Worker support",
"keywords": [
"anycable",
Expand All @@ -9,19 +9,20 @@
"visibility api"
],
"files": [
"lib/",
"dist/",
"README.md",
"LICENSE"
],
"main": "lib/index.cjs.js",
"module": "lib/index.esm.js",
"unpkg": "lib/index.umd.js",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"unpkg": "dist/index.umd.js",
"exports": {
".": {
"import": "./lib/index.esm.js",
"require": "./lib/index.cjs.js"
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
}
},
"types": "dist/index.esm.d.ts",
"author": "Alexey Vasiliev",
"license": "MIT",
"repository": "github:le0pard/cable-shared-worker",
Expand Down
1 change: 0 additions & 1 deletion packages/worker/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# production
dist
lib
15 changes: 8 additions & 7 deletions packages/worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cable-shared-worker/worker",
"version": "0.3.2",
"version": "0.4.0",
"description": "ActionCable and AnyCable Shared Worker support",
"keywords": [
"anycable",
Expand All @@ -9,19 +9,20 @@
"visibility api"
],
"files": [
"lib/",
"dist/",
"README.md",
"LICENSE"
],
"main": "lib/index.cjs.js",
"module": "lib/index.esm.js",
"unpkg": "lib/index.umd.js",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"unpkg": "dist/index.umd.js",
"exports": {
".": {
"import": "./lib/index.esm.js",
"require": "./lib/index.cjs.js"
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
}
},
"types": "dist/index.esm.d.ts",
"author": "Alexey Vasiliev",
"license": "MIT",
"repository": "github:le0pard/cable-shared-worker",
Expand Down
26 changes: 4 additions & 22 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import alias from '@rollup/plugin-alias'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import {babel} from '@rollup/plugin-babel'
import terser from '@rollup/plugin-terser'
// packages
import webPkg from './packages/web/package.json'
import workerPkg from './packages/worker/package.json'
Expand All @@ -15,9 +14,9 @@ const bannersParams = {
const LIBRARY_NAME = 'CableSW' // Library name
const EXTERNAL = [] // external modules
const GLOBALS = {} // https://rollupjs.org/guide/en/#outputglobals
const OUTPUT_DIR = 'lib'
const OUTPUT_DIR = 'dist'

const makeConfig = (env = 'development') => {
const makeConfig = () => {
const configs = Object.keys(bannersParams).map((name) => {
const banner = `/*!
* ${bannersParams[name].name}
Expand All @@ -30,7 +29,7 @@ const makeConfig = (env = 'development') => {
* @license ${bannersParams[name].license}
*/`

let config = {
return {
input: `packages/${name}/src/index.js`,
external: EXTERNAL,
output: [
Expand Down Expand Up @@ -72,28 +71,11 @@ const makeConfig = (env = 'development') => {
})
]
}

if (env === 'production') {
config.plugins.push(
terser({
sourceMap: true,
output: {
comments: /^!/
}
})
)
}

return config
})

return configs
}

export default (commandLineArgs) => {
if (commandLineArgs.environment === 'BUILD:production') {
return makeConfig('production')
}

export default () => {
return makeConfig()
}
31 changes: 31 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"include": [
"packages/web/dist/index.esm.js",
"packages/worker/dist/index.esm.js"
],
"compilerOptions": {
"allowJs": true,
// Avoid extra work
"checkJs": false,
// Ensure ".d.ts" modules are generated
"declaration": true,
"declarationMap": true,
// Prevent output to declaration directory
"declarationDir": null,
// Skip ".js" generation
"emitDeclarationOnly": true,
// Single file emission is impossible with this flag set
"isolatedModules": false,
// Generate single file
// `System`, in contrast to `None`, permits the use of `import.meta`
"module": "System",
// Always emit
"noEmit": false,
// Skip code generation when error occurs
"noEmitOnError": true,
// Ignore errors in library type definitions
"skipLibCheck": true,
// Always strip internal exports
"stripInternal": true
}
}
Loading

0 comments on commit a9185b7

Please sign in to comment.