Skip to content

Commit

Permalink
Rework the dts generation (#576)
Browse files Browse the repository at this point in the history
* Switch to using virtual _bundled directory

* js bundling works

* try to avoid using \0, still unsure what's better

* port preconstruct dts plkugin

* tweak

* fix cwd

* working dts emit without replacements

* fixed issues

* test change

* wip

* switch to vfs module

* make sure that unique ids are generated for bundled modules

* use the correct system 😭😭😭

* simplify bundled plugin

* fix resolve errors

* tweak resolve Errors plugin further

* ignore resolve errors for entries

* getting closer

* fix bundling scenarios

* rollback temp changes

* bring back dev dep

* fix build crashes with multiple bundled dependencies

* fix dep

* fix user agent thing

* remove redundant check from `esbuild` plugin

* small tweak

* call init functions where appropriate

* fix reference
  • Loading branch information
Andarist authored Jul 1, 2024
1 parent dd41fa8 commit adb0dff
Show file tree
Hide file tree
Showing 15 changed files with 644 additions and 221 deletions.
5 changes: 5 additions & 0 deletions packages/cypress/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import {
fetchWorkspaceConfig,
ReplayReporterConfig,
} from "@replayio/test-utils";
import * as pkgJson from "../package.json";
import dbg from "debug";

import { Errors } from "./error";
import { appendToFixtureFile, initFixtureFile } from "./fixture";
import { getTestsFromResults, groupStepsByTest, sortSteps } from "./steps";
import type { StepEvent } from "./support";
import { PluginFeature, getFeatures, isFeatureEnabled } from "./features";
import { setUserAgent } from "@replay-cli/shared/userAgent";
import { initLogger } from "@replay-cli/shared/logger";

type Test = TestMetadataV2.Test;

Expand Down Expand Up @@ -59,6 +62,8 @@ class CypressReporter {
private _extraEnv: NodeJS.ProcessEnv = {};

constructor(config: Cypress.PluginConfigOptions, options: PluginOptions) {
setUserAgent(`${pkgJson.name}/${pkgJson.version}`);
initLogger(pkgJson.name, pkgJson.version);
initFixtureFile();

this.config = config;
Expand Down
3 changes: 2 additions & 1 deletion packages/cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "@replay-cli/tsconfig/base.json",
"compilerOptions": {
"target": "es2022",
"lib": ["dom", "es2023"]
"lib": ["dom", "es2023"],
"resolveJsonModule": true
},
"include": ["src/**/*.ts"],
"references": [
Expand Down
1 change: 1 addition & 0 deletions packages/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@jest/test-result": "^27.5.1",
"@jest/types": "^27.5.1",
"@replay-cli/pkg-build": "workspace:^",
"@replay-cli/shared": "workspace:^",
"@replay-cli/tsconfig": "workspace:^",
"@replayio/test-utils": "workspace:^",
"@types/node": "^20.11.27",
Expand Down
5 changes: 5 additions & 0 deletions packages/jest/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
} from "@replayio/test-utils";
import type Runtime from "jest-runtime";
import path from "path";
import * as pkgJson from "../package.json";
import { setUserAgent } from "@replay-cli/shared/userAgent";
import { initLogger } from "@replay-cli/shared/logger";

const runner = require("jest-circus/runner");
const pluginVersion = require("@replayio/jest/package.json").version;
Expand All @@ -35,6 +38,8 @@ const ReplayRunner = async (
testPath: string,
sendMessageToJest?: TestFileEvent
): Promise<TestResult> => {
setUserAgent(`${pkgJson.name}/${pkgJson.version}`);
initLogger(pkgJson.name, pkgJson.version);
if (!version) {
try {
version = require(require.resolve("jest/package.json", {
Expand Down
4 changes: 3 additions & 1 deletion packages/jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "@replay-cli/tsconfig/base.json",
"compilerOptions": {},
"compilerOptions": {
"resolveJsonModule": true
},
"include": ["src/**/*.ts"],
"references": [
{
Expand Down
8 changes: 5 additions & 3 deletions packages/playwright/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { FixtureStepStart, ParsedErrorFrame, TestExecutionIdData } from "./fixtu
import { StackFrame } from "./playwrightTypes";
import { getServerPort, startServer } from "./server";
import { initLogger, logger } from "@replay-cli/shared/logger";
import packageJson from "../package.json";
import pkgJson from "../package.json";
import { setUserAgent } from "@replay-cli/shared/userAgent";

export function getMetadataFilePath(workerIndex = 0) {
return getMetadataFilePathBase("PLAYWRIGHT", workerIndex);
Expand Down Expand Up @@ -79,7 +80,8 @@ class ReplayPlaywrightReporter implements Reporter {
private _foundReplayBrowser = false;

constructor(config: ReplayPlaywrightConfig) {
initLogger(packageJson.name, packageJson.version);
setUserAgent(`${pkgJson.name}/${pkgJson.version}`);
initLogger(pkgJson.name, pkgJson.version);
if (!config || typeof config !== "object") {
throw new Error(
`Expected an object for @replayio/playwright/reporter configuration but received: ${config}`
Expand All @@ -91,7 +93,7 @@ class ReplayPlaywrightReporter implements Reporter {
{
name: "playwright",
version: undefined,
plugin: packageJson.version,
plugin: pkgJson.version,
},
"2.2.0",
{ ...this.config, metadataKey: "PLAYWRIGHT_REPLAY_METADATA" }
Expand Down
3 changes: 2 additions & 1 deletion packages/test-utils/src/legacy-cli/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import ProtocolClient from "./client";
import dbg, { logPath } from "./debug";
import { sanitize as sanitizeMetadata } from "./metadata";
import { Options, OriginalSourceEntry, RecordingMetadata, SourceMapEntry } from "./types";
import { defer, getUserAgent, isValidUUID, maybeLog } from "./utils";
import { defer, isValidUUID, maybeLog } from "./utils";
import { getUserAgent } from "@replay-cli/shared/userAgent";

const debug = dbg("replay:cli:upload");

Expand Down
11 changes: 1 addition & 10 deletions packages/test-utils/src/legacy-cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import dbg from "debug";
import { AgentOptions, Agent as HttpAgent } from "http";
import { Agent as HttpsAgent } from "https";
import path from "path";
import { name as packageName, version as packageVersion } from "../../package.json";

import { Options } from "./types";

Expand Down Expand Up @@ -65,14 +64,6 @@ function isValidUUID(str: unknown) {
return true;
}

function getNameAndVersion() {
return `${packageName}/${packageVersion}`;
}

function getUserAgent() {
return getNameAndVersion();
}

function getHttpAgent(server: string, agentOptions?: AgentOptions) {
const serverURL = new URL(server);
if (!agentOptions) {
Expand All @@ -88,4 +79,4 @@ function getHttpAgent(server: string, agentOptions?: AgentOptions) {
throw new Error(`Unsupported protocol: ${serverURL.protocol} for URL ${serverURL}`);
}

export { defer, getDirectory, getHttpAgent, getUserAgent, isValidUUID, maybeLog };
export { defer, getDirectory, getHttpAgent, isValidUUID, maybeLog };
5 changes: 1 addition & 4 deletions packages/test-utils/src/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { retryWithExponentialBackoff } from "@replay-cli/shared/async/retryOnFailure";
import { getAuthInfo } from "@replay-cli/shared/graphql/getAuthInfo";
import { queryGraphQL } from "@replay-cli/shared/graphql/queryGraphQL";
import { initLogger, logger } from "@replay-cli/shared/logger";
import { logger } from "@replay-cli/shared/logger";
import { UnstructuredMetadata } from "@replay-cli/shared/recording/types";
import { setUserAgent } from "@replay-cli/shared/userAgent";
import { spawnSync } from "child_process";
import { mkdirSync, writeFileSync } from "fs";
import assert from "node:assert/strict";
import { dirname } from "path";
import { v4 as uuid } from "uuid";
import * as pkgJson from "../package.json";
import { listAllRecordings, removeRecording, uploadRecording } from "./legacy-cli";
import { add, source as sourceMetadata, test as testMetadata } from "./legacy-cli/metadata";
import type { TestMetadataV1, TestMetadataV2 } from "./legacy-cli/metadata/test";
Expand Down Expand Up @@ -264,7 +262,6 @@ class ReplayReporter<TRecordingMetadata extends UnstructuredMetadata = Unstructu
schemaVersion: string,
config?: ReplayReporterConfig<TRecordingMetadata>
) {
setUserAgent(`${pkgJson.name}/${pkgJson.version}`);
this._runner = runner;
this._schemaVersion = schemaVersion;

Expand Down
3 changes: 1 addition & 2 deletions scripts/pkg-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
"bin": "./bin.js",
"dependencies": {
"@manypkg/get-packages": "^2.2.1",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@typescript/vfs": "^1.5.3",
"builtin-modules": "^3.3.0",
"chalk": "^4.1.2",
"esbuild": "^0.21.5",
"fast-glob": "^3.3.2",
"normalize-path": "^3.0.0",
"rollup": "^4.18.0",
"rollup-plugin-dts": "^6.1.1",
"tsx": "^4.15.7"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit adb0dff

Please sign in to comment.