Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create rc of analytics node #587

Merged
merged 6 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/friendly-birds-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@segment/analytics-plugin-validation': major
'@segment/analytics-core': minor
---

Migrate common code into core.
7 changes: 6 additions & 1 deletion constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ gen_enforced_dependency(WorkspaceCwd, DependencyIdent, DependencyRange2, Depende
\+ member(DependencyIdent, [
% Allow examples to use different versions of react and
'react', 'react-dom',
'@types/react'
'@types/react',
% Allow the usage of workspace^ -- there is a better way to do this =)
silesky marked this conversation as resolved.
Show resolved Hide resolved
'@segment/analytics-next',
'@segment/analytics-node',
'@segment/analytics-core',
'@internal/config'
]).

% Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`
Expand Down
3 changes: 3 additions & 0 deletions internal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @internal/*

Internal packages are private and never published to npm. Internal packages may _only_ be installed as devDependencies (if installed in a public package).
7 changes: 7 additions & 0 deletions internal/config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@internal/config",
"version": "0.0.0",
"private": true,
"main": "./src",
"packageManager": "[email protected]"
}
4 changes: 4 additions & 0 deletions internal/config/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
createJestTSConfig: require('./jest/config').createJestTSConfig,
lintStagedConfig: require('./lint-staged/config'),
}
34 changes: 34 additions & 0 deletions internal/config/src/jest/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { getJestModuleMap } = require('./get-module-map')

/**
* Create Config
* @param {import('jest').Config} Overrides.
* @param {object} getJestModuleMap options.
* @returns {import('jest').Config}
*/
const createJestTSConfig = (
{ modulePathIgnorePatterns, testMatch, ...overridesToMerge } = {},
{ packageRoot, skipPackageMap } = {}
) => {
return {
moduleNameMapper: getJestModuleMap(packageRoot, skipPackageMap),
preset: 'ts-jest',
modulePathIgnorePatterns: [
'<rootDir>/dist/',
...(modulePathIgnorePatterns || []),
],
testEnvironment: 'node',
testMatch: ['**/?(*.)+(test).[jt]s?(x)', ...(testMatch || [])],
clearMocks: true,
globals: {
'ts-jest': {
isolatedModules: true,
},
},
...(overridesToMerge || {}),
}
}

module.exports = {
createJestTSConfig,
}
31 changes: 31 additions & 0 deletions internal/config/src/jest/get-module-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const getPackages = require('get-monorepo-packages')

// do not map modules in CI to catch any package install bugs (slower)... not in use ATM
const doNotMapPackages = process.env.JEST_SKIP_PACKAGE_MAP === 'true'

/**
* Allows ts-jest to dynamically resolve packages so "build"
*/
const getJestModuleMap = (
packageRoot = '../../',
skipPackageMap = doNotMapPackages
) => {
// get listing of packages in the mono repo
const createLocation = (name) => {
return `<rootDir>/./${name}/src/$1`
}
const moduleNameMapper = getPackages(packageRoot).reduce(
(acc, el) => ({
...acc,
[`${el.package.name}(.*)$`]: createLocation(el.location),
}),
{}
)

return {
'@/(.+)': '<rootdir>/../../src/$1',
...(skipPackageMap ? {} : moduleNameMapper),
}
}

module.exports = { getJestModuleMap }
4 changes: 4 additions & 0 deletions internal/config/src/lint-staged/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'*.{js,jsx,ts,tsx}': ['eslint --fix'],
'*.json*': ['prettier --write'],
}
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
"version": "0.0.0",
"workspaces": [
"examples/*",
"packages/*"
"packages/*",
"internal/*"
],
"engines": {
"node": "^14.15.0"
},
"scripts": {
"test": "turbo run test",
"test": "FORCE_COLOR=1 turbo run test --filter='./packages/*'",
"test:scripts": "jest --config scripts/jest.config.js",
"lint": "yarn constraints && turbo run lint",
"build": "turbo run build",
"build:packages": "turbo run build --filter='./packages/*'",
"build": "turbo run build --filter='./packages/*'",
"watch": "turbo run watch --filter='./packages/*'",
"dev": "yarn workspace with-next-js run dev",
"postinstall": "husky install",
"changeset": "changeset",
"update-versions-and-changelogs": "changeset version && yarn version-run-all && bash scripts/update-lockfile.sh",
"release": "yarn build:packages --force && changeset publish && yarn postpublish-run-all && git push origin --tags --no-verify",
"release": "yarn build --force && changeset publish && yarn postpublish-run-all && git push origin --tags --no-verify",
"postpublish-run-all": "yarn workspaces foreach -vpt --no-private run postpublish",
"version-run-all": "yarn workspaces foreach -vpt --no-private run version",
"core": "yarn workspace @segment/analytics-core",
"core+deps": "turbo run --filter='analytics-core'",
"core+deps": "turbo run --filter=@segment/analytics-core...",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "..." syntax is how turborepo expresses "include all dependencies".

"browser": "yarn workspace @segment/analytics-next",
"browser+deps": "turbo run --filter='analytics-next'",
"browser+deps": "turbo run --filter=@segment/analytics-next...",
"node": "yarn workspace @segment/analytics-node",
"node+deps": "turbo run --filter='analytics-node'",
"node+deps": "turbo run --filter=@segment/analytics-node...",
"clean": "bash scripts/clean.sh"
},
"packageManager": "[email protected]",
Expand Down
4 changes: 1 addition & 3 deletions packages/browser/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
module.exports = {
'*.{js,jsx,ts,tsx}': ['eslint --fix'],
}
module.exports = require("@internal/config").lintStagedConfig
29 changes: 6 additions & 23 deletions packages/browser/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
module.exports = {
preset: 'ts-jest',
modulePathIgnorePatterns: [
'<rootDir>/dist/',
'<rootDir>/e2e-tests',
'<rootDir>/qa',
],
testEnvironment: 'jsdom',
testMatch: ["**/?(*.)+(test).[jt]s?(x)"],
clearMocks: true,
testEnvironmentOptions: {
resources: 'usable',
},
moduleNameMapper: {
'@/(.+)': '<rootdir>/../../src/$1',
},
const { createJestTSConfig } = require('@internal/config')

module.exports = createJestTSConfig({
modulePathIgnorePatterns: ['<rootDir>/e2e-tests', '<rootDir>/qa'],
setupFilesAfterEnv: ['./jest.setup.js'],
globals: {
'ts-jest': {
isolatedModules: true,
},
},
reporters: ['default'],
testEnvironment: 'jsdom',
coverageThreshold: {
global: {
branches: 80.91,
Expand All @@ -29,4 +12,4 @@ module.exports = {
statements: 87.25,
},
},
}
})
3 changes: 2 additions & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"tsc": "yarn run -T tsc",
"jest": "yarn run -T jest",
"concurrently": "yarn run -T concurrently",
"watch": "yarn concurrently 'NODE_ENV=production yarn umd --watch' 'yarn pkg --watch' 'yarn cjs --watch'",
"watch": "yarn concurrently 'NODE_ENV=production yarn umd --watch' 'yarn pkg --watch --incremental'",
"build": "yarn clean && yarn build-prep && yarn concurrently 'NODE_ENV=production yarn umd' 'yarn pkg' 'yarn cjs'",
"postpublish": "echo 'running postpublish build step...' && NODE_ENV=production PROD_RELEASE=true bash scripts/release.sh",
"pkg": "yarn tsc -p tsconfig.build.json",
Expand Down Expand Up @@ -60,6 +60,7 @@
"unfetch": "^4.1.0"
},
"devDependencies": {
"@internal/config": "0.0.0",
"@segment/inspector-webext": "^1.1.0",
"@size-limit/preset-big-lib": "^7.0.8",
"@types/flat": "^5.0.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/core-integration-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type { import('eslint').Linter.Config } */
module.exports = {
extends: ["../../.eslintrc"],
}
1 change: 1 addition & 0 deletions packages/core-integration-tests/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@internal/config").lintStagedConfig
2 changes: 2 additions & 0 deletions packages/core-integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Core tests that require AnalyticsBrowser, etc.
This exists because we can't create circular dependencies -- so, for example, installing AnalyticsBrowser as a dev dependency on core.
3 changes: 3 additions & 0 deletions packages/core-integration-tests/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { createJestTSConfig } = require('@internal/config')

module.exports = createJestTSConfig()
20 changes: 20 additions & 0 deletions packages/core-integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new package!

"name": "@internal/core-integration-tests",
"version": "0.0.0",
"private": true,
"scripts": {
"test": "yarn jest",
"lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'",
"watch:test": "yarn test --watch",
"tsc": "yarn run -T tsc",
"eslint": "yarn run -T eslint",
"concurrently": "yarn run -T concurrently",
"jest": "yarn run -T jest"
},
"packageManager": "[email protected]",
"devDependencies": {
"@internal/config": "workspace:^",
"@segment/analytics-core": "workspace:^",
"@segment/analytics-next": "workspace:^"
}
}
Loading