Skip to content

Commit

Permalink
fix(package): update dependencies and add more generic module path check
Browse files Browse the repository at this point in the history
release-npm
  • Loading branch information
tobua committed May 26, 2022
1 parent 70fdf8b commit 1e93640
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
"test": "jest"
},
"dependencies": {
"@babel/core": "^7.17.9",
"@babel/eslint-parser": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@types/jest": "^27.4.1",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"babel-jest": "^28.0.0",
"@babel/core": "^7.18.2",
"@babel/eslint-parser": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-react": "^7.17.12",
"@babel/preset-typescript": "^7.17.12",
"@types/jest": "^27.5.1",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"babel-jest": "^28.1.0",
"babel-loader": "^8.2.5",
"chalk": "^4.1.2",
"commander": "^9.2.0",
"copy-webpack-plugin": "^10.2.4",
"core-js": "^3.22.2",
"copy-webpack-plugin": "^11.0.0",
"core-js": "^3.22.7",
"css-loader": "^6.7.1",
"deep-for-each": "^3.0.0",
"deepmerge": "^4.2.2",
"ejs": "^3.1.7",
"eslint": "^8.14.0",
"ejs": "^3.1.8",
"eslint": "^8.16.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -37,26 +37,26 @@
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.4.0",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-react-hooks": "^4.5.0",
"fast-glob": "^3.2.11",
"favicons": "^6.2.2",
"favicons-webpack-plugin": "^5.0.2",
"file-loader": "^6.2.0",
"fork-ts-checker-webpack-plugin": "^7.2.7",
"fork-ts-checker-webpack-plugin": "^7.2.11",
"fs-extra": "^10.1.0",
"get-port": "^6.1.2",
"global-dirs": "^3.0.0",
"html-webpack-plugin": "^5.5.0",
"jest": "^28.0.0",
"jest": "^28.1.0",
"logua": "^2.1.4",
"mini-css-extract-plugin": "^2.6.0",
"node-html-parser": "^5.3.3",
"npm-check-updates": "^12.5.9",
"npm-check-updates": "^13.0.3",
"object-assign-deep": "^0.4.0",
"open": "^8.4.0",
"pakag": "^2.6.0",
"parse-gitignore": "^1.0.1",
"parse-gitignore": "^2.0.0",
"prettier": "^2.6.2",
"pretty-bytes": "^6.0.0",
"pretty-ms": "^7.0.1",
Expand All @@ -67,13 +67,13 @@
"skip-local-postinstall": "^2.0.3",
"snowpack": "^3.8.8",
"style-loader": "^3.3.1",
"stylelint": "^14.7.1",
"stylelint": "^14.8.5",
"stylelint-config-recommended": "^7.0.0",
"synec": "^0.2.2",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3",
"webpack": "^5.72.0",
"webpack-dev-server": "^4.8.1",
"ts-jest": "^28.0.3",
"typescript": "^4.7.2",
"webpack": "^5.72.1",
"webpack-dev-server": "^4.9.0",
"webpack-format-messages": "^3.0.1",
"workbox-webpack-plugin": "^6.5.3"
},
Expand Down
4 changes: 3 additions & 1 deletion script/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ export default async () => {
done()
}

return new Promise((done) => compiler.run(handler.bind(null, done)))
return new Promise((done) => {
compiler.run(handler.bind(null, done))
})
}
8 changes: 5 additions & 3 deletions utility/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const loadWebpackConfig = async (development) => {
let userConfiguration = {}
let afterMergeConfiguration
const userConfigurationPath = join(getProjectBasePath(), 'webpack.config.js')
const windowsFileProtocol = process.platform === "win32" ? 'file://' : ''
const windowsFileProtocol = process.platform === 'win32' ? 'file://' : ''

try {
// Works with module.exports = {} and export default {}.
Expand Down Expand Up @@ -125,12 +125,14 @@ export const loadWebpackConfig = async (development) => {
export const loadSnowpackConfig = async () => {
let configuration = await snowpackConfig()
let userConfiguration = {}
const windowsFileProtocol = process.platform === "win32" ? 'file://' : ''
const windowsFileProtocol = process.platform === 'win32' ? 'file://' : ''

try {
// Works with module.exports = {} and export default {}.
// The latter only if type in project is set to ES Modules.
userConfiguration = await import(`${windowsFileProtocol}${join(getProjectBasePath(), './snowpack.config.js')}`)
userConfiguration = await import(
`${windowsFileProtocol}${join(getProjectBasePath(), './snowpack.config.js')}`
)

if (userConfiguration.default) {
userConfiguration = userConfiguration.default
Expand Down
2 changes: 1 addition & 1 deletion utility/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const options = cache(() => {
packageContents = readFileSync(packageJsonPath, 'utf8')
packageContents = JSON.parse(packageContents)
} catch (error) {
log('unable to load package.json', 'error')
log('Unable to load package.json', 'error')
}

if (typeof packageContents.papua === 'object') {
Expand Down
19 changes: 17 additions & 2 deletions utility/path.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { join } from 'path'

// Required for pnpm as modules are nested deeper.
const inModules = (path) => path.includes('node_modules') && process.env.INIT_CWD
// More specific check but above more generic version should work with any package manager.
const packageInModules = (path) =>
path.includes('node_modules/papua') || path.includes('node_modules\\papua')

export const getProjectBasePath = () => {
// CWD during postinstall is in package, otherwise in project.
const currentWorkingDirectory = process.cwd()

if (currentWorkingDirectory.includes('node_modules/papua') || currentWorkingDirectory.includes('node_modules\\papua')) {
if (inModules(currentWorkingDirectory)) {
return process.env.INIT_CWD
}

if (packageInModules(currentWorkingDirectory)) {
return join(currentWorkingDirectory, '../..')
}

Expand All @@ -18,7 +28,12 @@ export const getPluginBasePath = () => {
return join(currentWorkingDirectory, '../../..')
}

if (!currentWorkingDirectory.includes('node_modules/papua') || !currentWorkingDirectory.includes('node_modules\\papua')) {
// Required for pnpm as modules are nested deeper.
if (!inModules(currentWorkingDirectory)) {
return join(process.env.INIT_CWD, 'node_modules/papua')
}

if (!packageInModules(currentWorkingDirectory)) {
return join(currentWorkingDirectory, 'node_modules/papua')
}

Expand Down

0 comments on commit 1e93640

Please sign in to comment.