Skip to content

Commit

Permalink
fix(package): do not add additional properties on CI
Browse files Browse the repository at this point in the history
Update project and fix path in exports file. release-npm

BREAKING CHANGE: Properties will no longer be added in postinstall script when run on CI.
  • Loading branch information
tobua committed Mar 6, 2024
1 parent 7eb0210 commit b5a6ffb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
8 changes: 4 additions & 4 deletions configuration/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ const switchable = (pkg) => {
'.': {
types: `./${options.output}/index.d.ts`,
// "default" condition must be last with most bundlers.
default: `./${options.output}/${pkg.main}`,
default: pkg.main,
},
}
} else {
pkg.exports = {
'.': {
default: `./${options.output}/${pkg.main}`,
default: pkg.main,
},
}
}
Expand All @@ -151,7 +151,7 @@ const switchable = (pkg) => {
pkg.scripts.test = 'padua test'
}

if (!pkg.jest) {
if (!pkg.jest && typeof Bun === 'undefined') {
pkg.jest = {
transform: {},
}
Expand All @@ -170,7 +170,7 @@ const switchable = (pkg) => {
]
}
}
} else if (pkg.jest) {
} else if (pkg.jest && typeof Bun === 'undefined') {
delete pkg.jest
}
}
Expand Down
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@
},
"dependencies": {
"@babel/eslint-parser": "^7.23.10",
"@babel/preset-env": "^7.23.9",
"@babel/preset-env": "^7.24.0",
"@manypkg/find-root": "^2.2.1",
"@npmcli/map-workspaces": "^3.0.4",
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"current-git-branch": "^1.1.0",
"deep-for-each": "^3.0.0",
"deepmerge": "^4.3.1",
"esbuild": "^0.20.0",
"eslint": "^8.56.0",
"esbuild": "^0.20.1",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.34.0",
"fast-glob": "^3.3.2",
"filesize": "^10.1.0",
"gzip-size": "^7.0.0",
Expand All @@ -39,7 +42,7 @@
"logua": "^3.0.3",
"npm-check-updates": "^16.14.15",
"pacote": "^17.0.6",
"pakag": "^3.1.1",
"pakag": "^3.1.3",
"parse-gitignore": "^2.0.0",
"prettier": "^3.2.5",
"skip-local-postinstall": "^2.0.4",
Expand All @@ -56,7 +59,7 @@
"source": "index.js",
"devDependencies": {
"jest-fixture": "^4.1.0",
"vitest": "^1.3.0"
"vitest": "^1.3.1"
},
"files": [
"configuration",
Expand All @@ -69,14 +72,12 @@
"build",
"plugin"
],
"overrides": {
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1"
},
"prettier": "./configuration/.prettierrc.json",
"eslintConfig": {
"extends": "./configuration/eslint.cjs",
"ignorePatterns": ["template"],
"ignorePatterns": [
"template"
],
"rules": {
"no-console": "off",
"import/extensions": [
Expand Down
2 changes: 2 additions & 0 deletions test/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ test('Does not override configuration changes made by user after initial install
expect(pkg.type).toBe(undefined)
expect(pkg.main).toBe('./dist/index.js')

Check failure on line 184 in test/configuration.test.js

View workflow job for this annotation

GitHub Actions / release

test/configuration.test.js > Does not override configuration changes made by user after initial installation.

AssertionError: expected undefined to be './dist/index.js' // Object.is equality - Expected: "./dist/index.js" + Received: undefined ❯ test/configuration.test.js:184:20
expect(pkg.exports['.'].types).not.toBeDefined()
expect(pkg.exports['.'].default).toBe('./dist/index.js')
})

test('eslintConfig extended when switching to source mode.', async () => {
Expand Down Expand Up @@ -285,6 +286,7 @@ test('Types will be added.', async () => {
expect(pkg.main).toBe('./dist/index.js')
expect(pkg.types).toBe('./dist/index.d.ts')
expect(pkg.files).toEqual(['dist'])
expect(pkg.exports['.'].default).toBe('./dist/index.js')
})

test('Files array is only changed initially.', async () => {
Expand Down
35 changes: 19 additions & 16 deletions utility/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ const writeUserAndPackageConfig = async (
userConfig,
packageConfig,
userTSConfigPath,
packageTSConfigPath
packageTSConfigPath,
) => {
try {
writeFileSync(
packageTSConfigPath,
await formatPackageJson(JSON.stringify(packageConfig), { sort: false })
await formatPackageJson(JSON.stringify(packageConfig), { sort: false }),
)
writeFileSync(
userTSConfigPath,
await formatPackageJson(JSON.stringify(userConfig), { sort: false })
await formatPackageJson(JSON.stringify(userConfig), { sort: false }),
)
} catch (_) {
log(`Couldn't write ${filename}, therefore this plugin might not work as expected`, 'warning')
Expand Down Expand Up @@ -58,7 +58,7 @@ const writeOnlyUserConfig = async (filename, userConfig, packageConfig, userTSCo
adaptConfigToRoot(packageConfig)
writeFileSync(
userTSConfigPath,
await formatPackageJson(JSON.stringify(merge(packageConfig, userConfig)), { sort: false })
await formatPackageJson(JSON.stringify(merge(packageConfig, userConfig)), { sort: false }),
)
} catch (_) {
log(`Couldn't write ${filename}, therefore this plugin might not work as expected`, 'warning')
Expand All @@ -69,12 +69,12 @@ const writePackageAndUserFile = async (
shouldRemove,
filename,
getConfiguration,
userConfigOverrides
userConfigOverrides,
) => {
const userTSConfigPath = join(getProjectBasePath(), `./${filename}`)
const packageTSConfigPath = join(
getProjectBasePath(),
`./node_modules/padua/configuration/${filename}`
`./node_modules/padua/configuration/${filename}`,
)

if (shouldRemove) {
Expand All @@ -92,14 +92,14 @@ const writePackageAndUserFile = async (
accessSync(
packageTSConfigPath,
// eslint-disable-next-line no-bitwise
constants.F_OK | constants.R_OK | constants.W_OK
constants.F_OK | constants.R_OK | constants.W_OK,
)
await writeUserAndPackageConfig(
filename,
userConfig,
packageConfig,
userTSConfigPath,
packageTSConfigPath
packageTSConfigPath,
)
} catch (_) {
// Package config cannot be written, write full contents to user file.
Expand All @@ -112,7 +112,7 @@ const writeTSConfig = async (tsConfigUserOverrides = {}) => {
!getOptions().typescript,
'tsconfig.json',
tsconfig,
tsConfigUserOverrides
tsConfigUserOverrides,
)
}

Expand All @@ -121,7 +121,7 @@ const writeJSConfig = async (jsConfigUserOverrides = {}) => {
getOptions().typescript,
'jsconfig.json',
jsconfig,
jsConfigUserOverrides
jsConfigUserOverrides,
)
}

Expand All @@ -134,7 +134,7 @@ const replaceIgnoresFor = (property, filePath, values) => {
if (match && Array.isArray(match) && match.length > 0) {
configurationContents = configurationContents.replace(
match[0],
`${property}: [${values.map((value) => `'${value}'`).join(', ')}],`
`${property}: [${values.map((value) => `'${value}'`).join(', ')}],`,
)
writeFileSync(filePath, configurationContents)
}
Expand Down Expand Up @@ -179,15 +179,15 @@ export const writeIgnore = async (ignores) => {
// Write ignores.
const prettierIgnorePath = join(
getProjectBasePath(),
`./node_modules/padua/configuration/.prettierignore`
`./node_modules/padua/configuration/.prettierignore`,
)
const eslintConfigurationPath = join(
getProjectBasePath(),
`./node_modules/padua/configuration/eslint.cjs`
`./node_modules/padua/configuration/eslint.cjs`,
)
const stylelintConfigurationPath = join(
getProjectBasePath(),
`./node_modules/padua/configuration/stylelint.cjs`
`./node_modules/padua/configuration/stylelint.cjs`,
)

if (!existsSync(prettierIgnorePath)) {
Expand All @@ -211,7 +211,7 @@ export const writeIgnore = async (ignores) => {
if (Array.isArray(packageJsonContents.jest.testPathIgnorePatterns)) {
packageJsonContents.jest.testPathIgnorePatterns =
packageJsonContents.jest.testPathIgnorePatterns.filter(
(pattern) => !ignoreValues.test.includes(pattern)
(pattern) => !ignoreValues.test.includes(pattern),
)
packageJsonContents.jest.testPathIgnorePatterns = [
...packageJsonContents.jest.testPathIgnorePatterns,
Expand Down Expand Up @@ -286,7 +286,10 @@ export const writePackageJson = async () => {

resetIgnoredProperties(contents)

await writePackageJsonFile(contents)
// Avoid adding additional properties in CI environment.
if (!isCI) {
await writePackageJsonFile(contents)
}

if (!contents.padua) {
contents.padua = {}
Expand Down

0 comments on commit b5a6ffb

Please sign in to comment.