Skip to content

Commit 598fc31

Browse files
authored
Create rc of analytics node (#587)
create analytics-node (priv ATM), @internal/config (priv), plugin-validation (public) Co-authored-by: Seth Silesky <[email protected]>
1 parent 8d94015 commit 598fc31

File tree

92 files changed

+5382
-114
lines changed

Some content is hidden

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

92 files changed

+5382
-114
lines changed

.changeset/friendly-birds-happen.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@segment/analytics-plugin-validation': major
3+
'@segment/analytics-core': minor
4+
---
5+
6+
Migrate common code into core.

constraints.pro

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ gen_enforced_dependency(WorkspaceCwd, DependencyIdent, DependencyRange2, Depende
2626
\+ member(DependencyIdent, [
2727
% Allow examples to use different versions of react and
2828
'react', 'react-dom',
29-
'@types/react'
29+
'@types/react',
30+
% Allow the usage of workspace^ -- there is a better way to do this =)
31+
'@segment/analytics-next',
32+
'@segment/analytics-node',
33+
'@segment/analytics-core',
34+
'@internal/config'
3035
]).
3136

3237
% Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`

internal/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @internal/*
2+
3+
Internal packages are private and never published to npm. Internal packages may _only_ be installed as devDependencies (if installed in a public package).

internal/config/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "@internal/config",
3+
"version": "0.0.0",
4+
"private": true,
5+
"main": "./src",
6+
"packageManager": "[email protected]"
7+
}

internal/config/src/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
createJestTSConfig: require('./jest/config').createJestTSConfig,
3+
lintStagedConfig: require('./lint-staged/config'),
4+
}

internal/config/src/jest/config.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const { getJestModuleMap } = require('./get-module-map')
2+
3+
/**
4+
* Create Config
5+
* @param {import('jest').Config} Overrides.
6+
* @param {object} getJestModuleMap options.
7+
* @returns {import('jest').Config}
8+
*/
9+
const createJestTSConfig = (
10+
{ modulePathIgnorePatterns, testMatch, ...overridesToMerge } = {},
11+
{ packageRoot, skipPackageMap } = {}
12+
) => {
13+
return {
14+
moduleNameMapper: getJestModuleMap(packageRoot, skipPackageMap),
15+
preset: 'ts-jest',
16+
modulePathIgnorePatterns: [
17+
'<rootDir>/dist/',
18+
...(modulePathIgnorePatterns || []),
19+
],
20+
testEnvironment: 'node',
21+
testMatch: ['**/?(*.)+(test).[jt]s?(x)', ...(testMatch || [])],
22+
clearMocks: true,
23+
globals: {
24+
'ts-jest': {
25+
isolatedModules: true,
26+
},
27+
},
28+
...(overridesToMerge || {}),
29+
}
30+
}
31+
32+
module.exports = {
33+
createJestTSConfig,
34+
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const getPackages = require('get-monorepo-packages')
2+
3+
// do not map modules in CI to catch any package install bugs (slower)... not in use ATM
4+
const doNotMapPackages = process.env.JEST_SKIP_PACKAGE_MAP === 'true'
5+
6+
/**
7+
* Allows ts-jest to dynamically resolve packages so "build"
8+
*/
9+
const getJestModuleMap = (
10+
packageRoot = '../../',
11+
skipPackageMap = doNotMapPackages
12+
) => {
13+
// get listing of packages in the mono repo
14+
const createLocation = (name) => {
15+
return `<rootDir>/./${name}/src/$1`
16+
}
17+
const moduleNameMapper = getPackages(packageRoot).reduce(
18+
(acc, el) => ({
19+
...acc,
20+
[`${el.package.name}(.*)$`]: createLocation(el.location),
21+
}),
22+
{}
23+
)
24+
25+
return {
26+
'@/(.+)': '<rootdir>/../../src/$1',
27+
...(skipPackageMap ? {} : moduleNameMapper),
28+
}
29+
}
30+
31+
module.exports = { getJestModuleMap }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
'*.{js,jsx,ts,tsx}': ['eslint --fix'],
3+
'*.json*': ['prettier --write'],
4+
}

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@
44
"version": "0.0.0",
55
"workspaces": [
66
"examples/*",
7-
"packages/*"
7+
"packages/*",
8+
"internal/*"
89
],
910
"engines": {
1011
"node": "^14.15.0"
1112
},
1213
"scripts": {
13-
"test": "turbo run test",
14+
"test": "FORCE_COLOR=1 turbo run test --filter='./packages/*'",
1415
"test:scripts": "jest --config scripts/jest.config.js",
1516
"lint": "yarn constraints && turbo run lint",
16-
"build": "turbo run build",
17-
"build:packages": "turbo run build --filter='./packages/*'",
17+
"build": "turbo run build --filter='./packages/*'",
1818
"watch": "turbo run watch --filter='./packages/*'",
1919
"dev": "yarn workspace with-next-js run dev",
2020
"postinstall": "husky install",
2121
"changeset": "changeset",
2222
"update-versions-and-changelogs": "changeset version && yarn version-run-all && bash scripts/update-lockfile.sh",
23-
"release": "yarn build:packages --force && changeset publish && yarn postpublish-run-all && git push origin --tags --no-verify",
23+
"release": "yarn build --force && changeset publish && yarn postpublish-run-all && git push origin --tags --no-verify",
2424
"postpublish-run-all": "yarn workspaces foreach -vpt --no-private run postpublish",
2525
"version-run-all": "yarn workspaces foreach -vpt --no-private run version",
2626
"core": "yarn workspace @segment/analytics-core",
27-
"core+deps": "turbo run --filter='analytics-core'",
27+
"core+deps": "turbo run --filter=@segment/analytics-core...",
2828
"browser": "yarn workspace @segment/analytics-next",
29-
"browser+deps": "turbo run --filter='analytics-next'",
29+
"browser+deps": "turbo run --filter=@segment/analytics-next...",
3030
"node": "yarn workspace @segment/analytics-node",
31-
"node+deps": "turbo run --filter='analytics-node'",
31+
"node+deps": "turbo run --filter=@segment/analytics-node...",
3232
"clean": "bash scripts/clean.sh"
3333
},
3434
"packageManager": "[email protected]",

packages/browser/.lintstagedrc.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
module.exports = {
2-
'*.{js,jsx,ts,tsx}': ['eslint --fix'],
3-
}
1+
module.exports = require("@internal/config").lintStagedConfig

packages/browser/jest.config.js

+6-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
1-
module.exports = {
2-
preset: 'ts-jest',
3-
modulePathIgnorePatterns: [
4-
'<rootDir>/dist/',
5-
'<rootDir>/e2e-tests',
6-
'<rootDir>/qa',
7-
],
8-
testEnvironment: 'jsdom',
9-
testMatch: ["**/?(*.)+(test).[jt]s?(x)"],
10-
clearMocks: true,
11-
testEnvironmentOptions: {
12-
resources: 'usable',
13-
},
14-
moduleNameMapper: {
15-
'@/(.+)': '<rootdir>/../../src/$1',
16-
},
1+
const { createJestTSConfig } = require('@internal/config')
2+
3+
module.exports = createJestTSConfig({
4+
modulePathIgnorePatterns: ['<rootDir>/e2e-tests', '<rootDir>/qa'],
175
setupFilesAfterEnv: ['./jest.setup.js'],
18-
globals: {
19-
'ts-jest': {
20-
isolatedModules: true,
21-
},
22-
},
23-
reporters: ['default'],
6+
testEnvironment: 'jsdom',
247
coverageThreshold: {
258
global: {
269
branches: 80.91,
@@ -29,4 +12,4 @@ module.exports = {
2912
statements: 87.25,
3013
},
3114
},
32-
}
15+
})

packages/browser/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"tsc": "yarn run -T tsc",
3232
"jest": "yarn run -T jest",
3333
"concurrently": "yarn run -T concurrently",
34-
"watch": "yarn concurrently 'NODE_ENV=production yarn umd --watch' 'yarn pkg --watch' 'yarn cjs --watch'",
34+
"watch": "yarn concurrently 'NODE_ENV=production yarn umd --watch' 'yarn pkg --watch --incremental'",
3535
"build": "yarn clean && yarn build-prep && yarn concurrently 'NODE_ENV=production yarn umd' 'yarn pkg' 'yarn cjs'",
3636
"postpublish": "echo 'running postpublish build step...' && NODE_ENV=production PROD_RELEASE=true bash scripts/release.sh",
3737
"pkg": "yarn tsc -p tsconfig.build.json",
@@ -60,6 +60,7 @@
6060
"unfetch": "^4.1.0"
6161
},
6262
"devDependencies": {
63+
"@internal/config": "0.0.0",
6364
"@segment/inspector-webext": "^1.1.0",
6465
"@size-limit/preset-big-lib": "^7.0.8",
6566
"@types/flat": "^5.0.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type { import('eslint').Linter.Config } */
2+
module.exports = {
3+
extends: ["../../.eslintrc"],
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("@internal/config").lintStagedConfig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Core tests that require AnalyticsBrowser, etc.
2+
This exists because we can't create circular dependencies -- so, for example, installing AnalyticsBrowser as a dev dependency on core.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { createJestTSConfig } = require('@internal/config')
2+
3+
module.exports = createJestTSConfig()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@internal/core-integration-tests",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"test": "yarn jest",
7+
"lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'",
8+
"watch:test": "yarn test --watch",
9+
"tsc": "yarn run -T tsc",
10+
"eslint": "yarn run -T eslint",
11+
"concurrently": "yarn run -T concurrently",
12+
"jest": "yarn run -T jest"
13+
},
14+
"packageManager": "[email protected]",
15+
"devDependencies": {
16+
"@internal/config": "workspace:^",
17+
"@segment/analytics-core": "workspace:^",
18+
"@segment/analytics-next": "workspace:^"
19+
}
20+
}

0 commit comments

Comments
 (0)