Skip to content

Commit 7fba629

Browse files
authored
chore(publish): Clean up non-existent exports and fix webpack mainFields for web target (#3084)
* chore(webpack-config-compass): Take `browser` field into account when resolving dependencies * chore: Clean-up non-existent export paths and add a prepublish check
1 parent 39f5911 commit 7fba629

File tree

52 files changed

+154
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+154
-91
lines changed

configs/webpack-config-compass/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"types": "./dist/index.d.ts",
3434
"scripts": {
3535
"bootstrap": "npm run compile",
36-
"prepublishOnly": "npm run compile",
36+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3737
"compile": "tsc -p tsconfig.json",
3838
"postcompile": "gen-esm-wrapper . ./dist/.esm-wrapper.mjs",
3939
"eslint": "eslint",

configs/webpack-config-compass/src/index.ts

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs';
2-
import type { WebpackPluginInstance } from 'webpack';
2+
import type { ResolveOptions, WebpackPluginInstance } from 'webpack';
33
import { merge } from 'webpack-merge';
44
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
55
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -31,10 +31,31 @@ import { sharedExternals } from './externals';
3131
import { WebpackPluginMulticompilerProgress } from './webpack-plugin-multicompiler-progress';
3232
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
3333

34-
const sharedResolveOptions = {
35-
mainFields: ['compass:module', 'compass:main', 'module', 'main'],
36-
exportsFields: ['compass:exports', 'exports'],
37-
extensions: ['.jsx', '.tsx', '.ts', '...'],
34+
const sharedResolveOptions = (
35+
target: ConfigArgs['target']
36+
): Pick<ResolveOptions, 'mainFields' | 'exportsFields' | 'extensions'> => {
37+
if (typeof target === 'string') {
38+
target = [target];
39+
}
40+
return {
41+
// This replicates webpack behavior with additional special `compass:` keys
42+
// taking priority over the default ones that webpack uses
43+
//
44+
// See https://webpack.js.org/configuration/resolve/#resolvemainfields
45+
mainFields:
46+
target?.includes('web') || target?.includes('webworker')
47+
? [
48+
'compass:browser',
49+
'compass:module',
50+
'compass:main',
51+
'browser',
52+
'module',
53+
'main',
54+
]
55+
: ['compass:module', 'compass:main', 'module', 'main'],
56+
exportsFields: ['compass:exports', 'exports'],
57+
extensions: ['.jsx', '.tsx', '.ts', '...'],
58+
};
3859
};
3960

4061
export function createElectronMainConfig(
@@ -69,7 +90,7 @@ export function createElectronMainConfig(
6990
resolve: {
7091
// To avoid resolving the `browser` field
7192
aliasFields: [],
72-
...sharedResolveOptions,
93+
...sharedResolveOptions(opts.target),
7394
},
7495
plugins: [new WebpackPluginMulticompilerProgress()],
7596
};
@@ -141,7 +162,7 @@ export function createElectronRendererConfig(
141162
resolve: {
142163
// To avoid resolving the `browser` field
143164
aliasFields: [],
144-
...sharedResolveOptions,
165+
...sharedResolveOptions(opts.target),
145166
},
146167
};
147168

@@ -254,7 +275,7 @@ export function createWebConfig(args: Partial<ConfigArgs>): WebpackConfig {
254275
...toCommonJsExternal(builtinModules),
255276
},
256277
resolve: {
257-
...sharedResolveOptions,
278+
...sharedResolveOptions(opts.target),
258279
},
259280
};
260281
}

package-lock.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-aggregations/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
".": "./src/index.js"
1515
},
1616
"scripts": {
17-
"prepublishOnly": "npm run compile",
17+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
1818
"compile": "npm run webpack -- --mode production",
1919
"prewebpack": "rimraf ./dist",
2020
"webpack": "webpack-compass",

packages/compass-app-stores/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test-electron": "xvfb-maybe cross-env NODE_ENV=test karma start",
2121
"test-cov": "nyc npm run test",
2222
"check": "npm run lint && npm run depcheck",
23-
"prepublishOnly": "npm run compile",
23+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2424
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
2525
"depcheck": "depcheck",
2626
"test-ci": "npm run test",

packages/compass-auto-updates/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test-electron": "xvfb-maybe cross-env NODE_ENV=test karma start",
2121
"test-cov": "nyc npm run test",
2222
"check": "npm run lint && npm run depcheck",
23-
"prepublishOnly": "npm run compile",
23+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2424
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
2525
"depcheck": "depcheck",
2626
"test-ci": "npm run test",
+10-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
ignores:
2-
- "@mongodb-js/prettier-config-compass"
3-
- "@mongodb-js/tsconfig-compass"
4-
- "@types/chai"
5-
- "@types/sinon-chai"
6-
- "sinon"
7-
- "@types/chai-dom"
8-
- "@types/react"
9-
- "@types/react-dom"
2+
- '@mongodb-js/prettier-config-compass'
3+
- '@mongodb-js/tsconfig-compass'
4+
- '@types/chai'
5+
- '@types/sinon-chai'
6+
- 'sinon'
7+
- '@types/chai-dom'
8+
- '@types/react'
9+
- '@types/react-dom'
10+
ignore-patterns:
11+
- 'dist'

packages/compass-collection/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
"compass:exports": {
3434
".": "./src/index.ts"
3535
},
36-
"types": "./dist/index.d.ts",
3736
"scripts": {
3837
"bootstrap": "npm run compile",
39-
"prepublishOnly": "npm run compile",
40-
"compile": "tsc -p tsconfig.json",
38+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
39+
"compile": "npm run webpack -- --mode production",
40+
"prewebpack": "rimraf ./dist",
41+
"webpack": "webpack-compass",
4142
"precompile": "rimraf dist",
4243
"eslint": "eslint",
4344
"prettier": "prettier",

packages/compass-components/package.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
"license": "SSPL",
66
"main": "lib/index.js",
77
"compass:main": "src/index.ts",
8-
"exports": {
9-
"types": "./lib/index.d.ts",
10-
"require": "./lib/index.js",
11-
"import": "./lib/.esm-wrapper.mjs"
12-
},
138
"compass:exports": {
149
".": "./src/index.ts"
1510
},
@@ -19,7 +14,7 @@
1914
],
2015
"scripts": {
2116
"bootstrap": "npm run compile",
22-
"prepublishOnly": "npm run compile",
17+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2318
"clean": "rimraf lib",
2419
"precompile": "npm run clean",
2520
"compile": "tsc -p tsconfig.json",

packages/compass-connections/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@
2424
"license": "SSPL",
2525
"main": "dist/index.js",
2626
"compass:main": "src/index.ts",
27-
"exports": {
28-
"require": "./dist/index.js",
29-
"import": "./dist/.esm-wrapper.mjs"
30-
},
3127
"compass:exports": {
3228
".": "./src/index.ts"
3329
},
3430
"types": "./dist/index.d.ts",
3531
"scripts": {
3632
"bootstrap": "npm run compile",
37-
"prepublishOnly": "npm run compile",
33+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3834
"compile": "tsc -p tsconfig.json",
3935
"precompile": "rimraf dist",
4036
"eslint": "eslint",

packages/compass-crud/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
},
1010
"main": "lib/index.js",
1111
"compass:main": "src/index.js",
12-
"types": "lib/index.d.ts",
1312
"compass:exports": {
1413
".": "./src/index.js"
1514
},
@@ -29,7 +28,7 @@
2928
"depcheck": "depcheck",
3029
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
3130
"check": "npm run depcheck && npm run lint",
32-
"prepublishOnly": "npm run compile",
31+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3332
"test-ci": "npm run test",
3433
"posttest-ci": "node ../../scripts/killall-mongo.js",
3534
"bootstrap": "npm run compile"

packages/compass-database/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test-electron": "xvfb-maybe cross-env NODE_ENV=test karma start",
2121
"test-cov": "nyc npm run test",
2222
"check": "npm run lint && npm run depcheck",
23-
"prepublishOnly": "npm run compile",
23+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2424
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
2525
"depcheck": "depcheck",
2626
"test-ci": "npm run test",

packages/compass-databases-navigation/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"scripts": {
3535
"bootstrap": "npm run compile",
36-
"prepublishOnly": "npm run compile",
36+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3737
"compile": "tsc -p tsconfig.json && gen-esm-wrapper . ./dist/.esm-wrapper.mjs",
3838
"eslint": "eslint",
3939
"prettier": "prettier",

packages/compass-deployment-awareness/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"test-electron": "xvfb-maybe cross-env NODE_ENV=test karma start",
2525
"test-cov": "nyc npm run test",
2626
"check": "npm run lint && npm run depcheck",
27-
"prepublishOnly": "npm run compile",
27+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2828
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
2929
"depcheck": "depcheck",
3030
"test-ci": "npm run test",

packages/compass-explain-plan/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232
"compass:exports": {
3333
".": "./src/index.js"
3434
},
35-
"types": "./dist/index.d.ts",
3635
"scripts": {
37-
"prepublishOnly": "npm run compile",
36+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3837
"compile": "npm run webpack -- --mode production",
3938
"prewebpack": "rimraf ./dist",
4039
"webpack": "webpack-compass",

packages/compass-export-to-language/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test-electron": "xvfb-maybe cross-env NODE_ENV=test karma start",
2121
"test-cov": "nyc npm run test",
2222
"check": "npm run lint && npm run depcheck",
23-
"prepublishOnly": "npm run compile",
23+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2424
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
2525
"depcheck": "depcheck",
2626
"test-ci": "npm run test",

packages/compass-field-store/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"depcheck": "depcheck",
2525
"test-ci": "npm run test",
2626
"test-ci-electron": "echo \"TODO(COMPASS-5555): These tests are broken and disabled for now\"",
27-
"prepublishOnly": "npm run compile",
27+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2828
"bootstrap": "npm run compile"
2929
},
3030
"license": "SSPL",

packages/compass-find-in-page/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
"compass:exports": {
3232
".": "./src/index.ts"
3333
},
34-
"types": "./dist/index.d.ts",
3534
"scripts": {
36-
"prepublishOnly": "npm run compile",
35+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3736
"compile": "npm run webpack -- --mode production",
3837
"prewebpack": "rimraf ./dist",
3938
"webpack": "webpack-compass",

packages/compass-home/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"cover": "nyc npm run test",
2626
"check": "npm run lint && npm run depcheck",
2727
"eslint": "eslint",
28-
"prepublishOnly": "npm run compile",
28+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2929
"lint": "npm run eslint . && npm run prettier -- --check .",
3030
"depcheck": "depcheck",
3131
"start": "echo \"There is not an electron running environment available for this package. Please run `npm start` from the root to run this.\"",

packages/compass-import-export/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
"compass:exports": {
3232
".": "./src/index.ts"
3333
},
34-
"types": "./dist/index.d.ts",
3534
"scripts": {
36-
"prepublishOnly": "npm run compile",
35+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3736
"compile": "npm run webpack -- --mode production",
3837
"prewebpack": "rimraf ./dist",
3938
"webpack": "webpack-compass",

packages/compass-indexes/.depcheckrc

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ ignores:
77
- '@types/chai-dom'
88
- '@types/react'
99
- '@types/react-dom'
10+
ignore-patterns:
11+
- 'dist'

packages/compass-indexes/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232
"compass:exports": {
3333
".": "./src/index.js"
3434
},
35-
"types": "./dist/index.d.ts",
3635
"scripts": {
37-
"prepublishOnly": "npm run compile",
36+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3837
"compile": "npm run webpack -- --mode production",
3938
"prewebpack": "rimraf ./dist",
4039
"webpack": "webpack-compass",

packages/compass-instance/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"test-electron": "xvfb-maybe cross-env NODE_ENV=test karma start",
2525
"test-cov": "nyc npm run test",
2626
"check": "npm run lint && npm run depcheck",
27-
"prepublishOnly": "npm run compile",
27+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2828
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
2929
"depcheck": "depcheck",
3030
"test-ci": "npm run test",

packages/compass-logging/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"types": "./dist/index.d.ts",
3434
"scripts": {
3535
"bootstrap": "npm run compile",
36-
"prepublishOnly": "npm run compile",
36+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3737
"compile": "tsc -p tsconfig.json",
3838
"eslint": "eslint",
3939
"prettier": "prettier",

packages/compass-plugin-info/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test-electron": "xvfb-maybe cross-env NODE_ENV=test karma start",
2121
"test-cov": "nyc npm run test",
2222
"check": "npm run lint && npm run depcheck",
23-
"prepublishOnly": "npm run compile",
23+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2424
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
2525
"depcheck": "depcheck",
2626
"test-ci": "npm run test",

packages/compass-query-bar/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"test-electron": "xvfb-maybe cross-env NODE_ENV=test karma start",
3535
"test-cov": "nyc npm run test",
3636
"check": "npm run lint && npm run depcheck",
37-
"prepublishOnly": "npm run compile",
37+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3838
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
3939
"depcheck": "depcheck",
4040
"test-ci": "npm run test",

packages/compass-query-history/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"test-electron": "xvfb-maybe cross-env NODE_ENV=test karma start",
3636
"test-cov": "nyc npm run test",
3737
"check": "npm run lint && npm run depcheck",
38-
"prepublishOnly": "npm run compile",
38+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3939
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
4040
"depcheck": "depcheck",
4141
"test-ci": "npm run test",

packages/compass-saved-aggregations-queries/.depcheckrc

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ ignores:
77
- '@types/chai-dom'
88
- '@types/react'
99
- '@types/react-dom'
10-
# Will come in handy when we will start to add tests
11-
- '@testing-library/react'
12-
- '@testing-library/user-event'
10+
ignore-patterns:
11+
- 'dist'
12+

packages/compass-saved-aggregations-queries/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
"compass:exports": {
3232
".": "./src/index.ts"
3333
},
34-
"types": "./dist/index.d.ts",
3534
"scripts": {
36-
"prepublishOnly": "npm run compile",
35+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3736
"compile": "npm run webpack -- --mode production",
3837
"prewebpack": "rimraf ./dist",
3938
"webpack": "webpack-compass",

packages/compass-schema-validation/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"cover": "nyc npm run test",
2525
"test-check-ci": "npm run cover && npm run compile && npm run check",
2626
"check": "npm run lint && npm run depcheck",
27-
"prepublishOnly": "npm run compile",
27+
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
2828
"lint": "eslint \"./src/**/*.{js,jsx}\" \"./test/**/*.js\" \"./electron/**/*.js\" \"./config/**/*.{js,jsx}\"",
2929
"depcheck": "depcheck",
3030
"test-ci": "npm run test",

packages/compass-schema/.depcheckrc

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ ignores:
22
- '@mongodb-js/prettier-config-compass'
33
- '@mongodb-js/tsconfig-compass'
44
- '@mongodb-js/tsconfig-compass'
5-
- "@types/react"
6-
- "@types/react-dom"
7-
- "@types/chai"
5+
- '@types/react'
6+
- '@types/react-dom'
7+
- '@types/chai'
8+
ignore-patterns:
9+
- 'dist'

0 commit comments

Comments
 (0)