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 <silesky@users.noreply.github.com>
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
Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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": "yarn@3.2.1"
7+
}

internal/config/src/index.js

Lines changed: 4 additions & 0 deletions
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

Lines changed: 34 additions & 0 deletions
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+
}
Lines changed: 31 additions & 0 deletions
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 }
Lines changed: 4 additions & 0 deletions
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

Lines changed: 8 additions & 8 deletions
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": "yarn@3.2.1",

packages/browser/.lintstagedrc.js

Lines changed: 1 addition & 3 deletions
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

0 commit comments

Comments
 (0)