Skip to content

Commit

Permalink
fix: strict mode, paths fix
Browse files Browse the repository at this point in the history
closes #16, #17
  • Loading branch information
Marty Mcfly committed Nov 7, 2019
1 parent ad7b8c4 commit e945be6
Show file tree
Hide file tree
Showing 40 changed files with 309 additions and 204 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

# optional
[*]
end_of_line = lf
insert_final_newline = true
indent_style = slace
indent_size = 2
charset = utf-8
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.rpt2_cache*
logs
*.lock
*.log
pids
*.pid
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module.exports = {
'tsConfig': 'tsconfig.jest.json'
}
},
//testEnvironment: "node",
testURL: "http://localhost",
};
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@
"scripts": {
"clean": "rm -rf packages/*/.rpt2_cache packages/*/dist",
"clean.all": "lerna clean --yes && rm -rf package-lock.json packages/*/package-lock.json node_modules packages/*/.rpt2_cache packages/*/dist docs/*",
"up": "ncu -ua ; npx lerna exec -- ncu -ua; npm run clean.all; npm install",
"up": "ncu -u; npx lerna exec -- ncu -u; yarn clean.all; yarn",
"build": "rollup -c rollup.config.js",
"dev": "rollup -w -c rollup.config.js",
"postinstall": "lerna bootstrap --hoist --no-ci",
"publish": "npm run build && lerna publish --conventional-commits --yes",
"publish": "yarn build && lerna publish --conventional-commits --yes",
"watch": "chokidar --initial -d 2000 -t 1000 'packages/*/dist/**' -c 'npm run build && cp -rvf packages/*/dist/* $npm_package_config_dest/node_modules/@zerollup'",
"test": "jest",
"test.watch": "jest --watch"
},
"workspaces": [
"packages/*"
],
"author": {
"name": "Stefan Zerkalica",
"email": "[email protected]"
},
"license": "ISC",
"devDependencies": {
"@types/jest": "^23.3.14",
"@types/node": "^10.14.18",
"chokidar-cli": "^1.2.3",
"jest": "^23.6.0",
"lerna": "^3.16.4",
"rollup": "^0.67.4",
"ts-jest": "^23.10.5",
"typescript": "^3.6.3"
"@types/jest": "^24.0.22",
"@types/node": "^12.12.6",
"chokidar-cli": "^2.1.0",
"jest": "^24.9.0",
"lerna": "^3.18.3",
"rollup": "^1.26.3",
"ts-jest": "^24.1.0",
"typescript": "3.7.2"
}
}
2 changes: 1 addition & 1 deletion packages/base-url/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"bugs": {
"url": "https://github.com/zerkalica/zerollup/issues"
},
"homepage": "https://github.com/zerkalica/zerollup/packages/base-url/#readme",
"homepage": "https://github.com/zerkalica/zerollup/tree/master/packages/base-url/#readme",
"main": "dist/index.js",
"module": "dist/index.mjs",
"typings": "dist/index.d.ts",
Expand Down
12 changes: 6 additions & 6 deletions packages/helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"bugs": {
"url": "https://github.com/zerkalica/zerollup/issues"
},
"homepage": "https://github.com/zerkalica/zerollup/packages/helpers/#readme",
"homepage": "https://github.com/zerkalica/zerollup/tree/master/packages/helpers/#readme",
"main": "dist/index.js",
"module": "dist/index.mjs",
"typings": "dist/index.d.ts",
Expand All @@ -35,13 +35,13 @@
"assets path"
],
"devDependencies": {
"@types/fs-extra": "^5.0.4"
"@types/fs-extra": "^8.0.1"
},
"dependencies": {
"builtins": "^2.0.0",
"change-case": "^3.0.2",
"fs-extra": "^7.0.1",
"globby": "^8.0.1",
"builtins": "^2.0.1",
"change-case": "^3.1.0",
"fs-extra": "^8.1.0",
"globby": "^10.0.1",
"node-eval": "^2.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/helpers/src/getAdvancedInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface AdvancedInfo {
export function getAdvancedInfo(
{pkg, aliases, globals, oneOfHost}: {
pkg: NormalizedPkg
oneOfHost?: string[] | void
oneOfHost?: string[] | undefined
aliases: Record<string, string>
globals: Record<string, string>
}
Expand Down
1 change: 1 addition & 0 deletions packages/helpers/src/getNamedExports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fsExtra from 'fs-extra'
// @ts-ignore
import nodeEval from 'node-eval'

function getModuleExports(moduleId: string): Promise<string[]> {
Expand Down
9 changes: 5 additions & 4 deletions packages/helpers/src/getPackageJson/getPackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {HelpersError} from '../interfaces'
import {getConfigs, Configs} from './getConfigs'
import {detectInputs} from './detectInputs'

//@ts-ignore
import getBuiltins from 'builtins'

export class GetPackageJsonError extends HelpersError {}
Expand Down Expand Up @@ -59,18 +60,18 @@ export interface NormalizedPkg {
declarationDir: string
globalName: string
srcDir: string
configs?: Configs | void
configs?: Configs | undefined
inputs: string[]
targets: Target[]
external: string[]
}

const allSections: SectionRec[] = [
const allSections = [
{key: 'module', format: 'es', ext: 'mjs'},
{key: 'main', format: 'cjs', ext: 'cjs.js'},
{key: 'umd:main', format: 'umd', ext: 'js'},
{key: 'iife:main', format: 'iife', ext: 'js'}
]
] as const

const builtins = getBuiltins()

Expand All @@ -79,7 +80,7 @@ function normalizePkg(pkg: Pkg, pkgPath: string): Promise<NormalizedPkg> {
const targets: Target[] = allSections
.filter(sec => !!pkg[sec.key])
.map(({key, format, ext}) => {
const val = pkg[key]
const val = pkg[key]!
return <Target> {
key,
format,
Expand Down
14 changes: 7 additions & 7 deletions packages/helpers/src/getPackageSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface LernaJson {
packages: string[]
}

function pathExistsUpLoop([config, exists, step]) {
function pathExistsUpLoop([config, exists, step]: [string, boolean, number]) {
if (exists) return config
const newStep = step - 1
if (newStep <= 0) return
Expand All @@ -39,11 +39,11 @@ function getLernaPackages(repoRoot: string): Promise<{pkgFiles: string[], repoRo
)
}

function getGlobals(pkgs: NormalizedPkg[]): Record<string, string> {
function getGlobals(pkgs: NormalizedPkg[]) {
return pkgs.reduce((acc, {json: {name}, globalName}) => {
acc[name] = globalName
return acc
}, {})
}, {} as Record<string, string>)
}

function getAliases(
Expand Down Expand Up @@ -76,8 +76,8 @@ function getAliases(
}

export function sortPackages({json: p1}: NormalizedPkg, {json: p2}: NormalizedPkg): number {
const deps1 = {...p1.dependencies, ...p1.devDependencies, ...p1.peerDependencies}
const deps2 = {...p2.dependencies, ...p2.devDependencies, ...p2.peerDependencies}
const deps1: Record<string, string> = {...p1.dependencies, ...p1.devDependencies, ...p1.peerDependencies}
const deps2: Record<string, string> = {...p2.dependencies, ...p2.devDependencies, ...p2.peerDependencies}
if (deps1[p2.name] || p1.name > p2.name) return 1
if (deps2[p1.name] || p1.name < p2.name) return -1
return 0
Expand All @@ -94,8 +94,8 @@ export function getPackageSet(
{pkgRoot, selectedNames: selNames, oneOfHost, env: rawEnv}: {
pkgRoot: string
env: string
oneOfHost?: string[] | void
selectedNames?: string[] | void
oneOfHost?: string[] | undefined
selectedNames?: string[] | undefined
}
): Promise<PackageSetInfo> {
const env: Env = getEnv(rawEnv)
Expand Down
6 changes: 3 additions & 3 deletions packages/helpers/src/nameHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ export function fixPath(name: string): string {

export function packagesToGlobalNames(
external: string[],
excludeMap: {[pkgName: string]: string} = {}
): {[pkgName: string]: string} {
excludeMap: Record<string, string> = {}
) {
return external.reduce((globalsMap, pkgName) => {
globalsMap[pkgName] = excludeMap[pkgName] || normalizeUmdName(pkgName)
return globalsMap
}, {})
}, {} as Record<string, string>)
}

export function cutExt(input: string): string {
Expand Down
10 changes: 5 additions & 5 deletions packages/rollup-plugin-assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"bugs": {
"url": "https://github.com/zerkalica/zerollup/issues"
},
"homepage": "https://github.com/zerkalica/zerollup/packages/rollup-plugin-assets/#readme",
"homepage": "https://github.com/zerkalica/zerollup/packages/tree/master/rollup-plugin-assets/#readme",
"main": "dist/index.js",
"module": "dist/index.mjs",
"typings": "dist/index.d.ts",
Expand All @@ -35,14 +35,14 @@
"assets path"
],
"peerDependencies": {
"rollup": "=>0.57.1"
"rollup": "*"
},
"dependencies": {
"@zerollup/helpers": "^1.7.1",
"fs-extra": "^7.0.1",
"rollup-pluginutils": "^2.3.3"
"fs-extra": "^8.1.0",
"rollup-pluginutils": "^2.8.2"
},
"devDependencies": {
"@types/fs-extra": "^5.0.4"
"@types/fs-extra": "^8.0.1"
}
}
6 changes: 3 additions & 3 deletions packages/rollup-plugin-assets/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Plugin, OutputOptions, OutputBundle} from 'rollup'
import {Plugin, OutputOptions, OutputBundle, LoadHook} from 'rollup'
import {readFile} from 'fs-extra'
import * as path from 'path'
import {createFilter} from 'rollup-pluginutils'
Expand Down Expand Up @@ -46,10 +46,10 @@ export default function assets(

return {
name,
load(id: string): void | string {
load(id: string): ReturnType<LoadHook> {
if (!filter(id)) {
collector.addToSearch(id)
return
return null
}

const relativeUrl = collector.addResource(id)
Expand Down
8 changes: 4 additions & 4 deletions packages/rollup-plugin-notify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"bugs": {
"url": "https://github.com/zerkalica/zerollup/issues"
},
"homepage": "https://github.com/zerkalica/zerollup/packages/rollup-plugin-notify/#readme",
"homepage": "https://github.com/zerkalica/zerollup/packages/tree/master/rollup-plugin-notify/#readme",
"main": "dist/index.js",
"module": "dist/index.mjs",
"typings": "dist/index.d.ts",
Expand All @@ -35,12 +35,12 @@
"assets path"
],
"peerDependencies": {
"rollup": "=>0.57.1"
"rollup": "*"
},
"dependencies": {
"node-notifier": "^5.3.0"
"node-notifier": "^6.0.0"
},
"devDependencies": {
"@types/node-notifier": "0.0.28"
"@types/node-notifier": "5.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/rollup-plugin-notify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function notify(
} = {}
): rollup.Plugin {
const name = '@zerollup/rollup-plugin-notify'
let handler
let handler: NodeJS.Timeout | null = null
return {
name,
watchChange(id: string) {
Expand Down
4 changes: 2 additions & 2 deletions packages/rollup-plugin-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"bugs": {
"url": "https://github.com/zerkalica/zerollup/issues"
},
"homepage": "https://github.com/zerkalica/zerollup/packages/rollup-plugin-template/#readme",
"homepage": "https://github.com/zerkalica/zerollup/packages/tree/master/rollup-plugin-template/#readme",
"main": "dist/index.js",
"module": "dist/index.mjs",
"typings": "dist/index.d.ts",
Expand All @@ -35,7 +35,7 @@
"assets path"
],
"peerDependencies": {
"rollup": "=>0.57.1"
"rollup": "*"
},
"dependencies": {
"@zerollup/helpers": "^1.7.1",
Expand Down
9 changes: 5 additions & 4 deletions packages/rollup-plugin-template/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class TemplatePluginFactory<Config> {
bundleCollector(pluginOpts: {env: string}): Plugin {
const {opts, bundles} = this
let resolve: (v: BundleRec[]) => void
const bundlePromise: Promise<BundleRec[]> = new Promise((res: (string) => void) => {
const bundlePromise = new Promise<BundleRec[]>((res: (v: BundleRec[]) => void) => {
resolve = res
})
bundles.push(bundlePromise)
Expand All @@ -42,10 +42,11 @@ export default class TemplatePluginFactory<Config> {
if ((opts.allowedExts || defaultExts).indexOf(getExt(key)) === -1) continue
const chunk = bundle[key]
if (!chunk) continue
let data: string
let data: string | undefined
if (typeof chunk === 'string') data = chunk
else if (chunk instanceof Buffer) data = chunk.toString()
else if (typeof chunk === 'object') data = chunk.code
else if (chunk && chunk.type === 'chunk') data = chunk.code
else if (chunk && chunk.type === 'asset') data = chunk.fileName
if (data) {
recs.push({
data,
Expand Down Expand Up @@ -88,7 +89,7 @@ export default class TemplatePluginFactory<Config> {

const configData: string = chunk instanceof Buffer
? chunk.toString()
: (typeof chunk === 'object' ? chunk.code : chunk)
: chunk && chunk.type === 'chunk' ? chunk.code : ''

return bundlesPromises
.then(bundles => {
Expand Down
Loading

0 comments on commit e945be6

Please sign in to comment.