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

[Snyk] Upgrade @segment/analytics-next from 1.53.0 to 1.69.0 #18

Open
wants to merge 12 commits into
base: Canary
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion examples/with-apollo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dependencies": {
"@apollo/client": "3.1.1",
"deepmerge": "^4.2.2",
"lodash": "4.17.20",
"lodash": "4.17.21",
"graphql": "^15.3.0",
"next": "latest",
"prop-types": "^15.6.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-clerk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/node": "20.5.7",
"@types/react": "18.2.8",
"@types/react-dom": "18.2.7",
"next": "13.4.2",
"next": "13.5.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.2.2"
Expand Down
2 changes: 1 addition & 1 deletion examples/with-segment-analytics-pages-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "next start"
},
"dependencies": {
"@segment/analytics-next": "1.53.0",
"@segment/analytics-next": "1.69.0",
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@
"ky-universal": "0.6.0",
"lerna": "4.0.0",
"lint-staged": "10.1.7",
"lodash": "4.17.20",
"lodash": "4.17.21",
"lost": "8.3.1",
"minimatch": "3.0.4",
"moment": "^2.24.0",
"nanoid": "3.1.30",
"nanoid": "3.1.31",
"next": "workspace:*",
"node-fetch": "2.6.7",
"node-plop": "0.31.1",
Expand Down
101 changes: 97 additions & 4 deletions packages/next-swc/crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub async fn project_update(

#[napi(object)]
#[derive(Default)]
struct NapiRoute {
pub struct NapiRoute {
/// The relative path from project_path to the route file
pub pathname: String,

Expand Down Expand Up @@ -367,7 +367,7 @@ impl NapiRoute {
}

#[napi(object)]
struct NapiMiddleware {
pub struct NapiMiddleware {
pub endpoint: External<ExternalEndpoint>,
}

Expand All @@ -386,7 +386,7 @@ impl NapiMiddleware {
}

#[napi(object)]
struct NapiInstrumentation {
pub struct NapiInstrumentation {
pub node_js: External<ExternalEndpoint>,
pub edge: External<ExternalEndpoint>,
}
Expand All @@ -410,7 +410,7 @@ impl NapiInstrumentation {
}

#[napi(object)]
struct NapiEntrypoints {
pub struct NapiEntrypoints {
pub routes: Vec<NapiRoute>,
pub middleware: Option<NapiMiddleware>,
pub instrumentation: Option<NapiInstrumentation>,
Expand Down Expand Up @@ -442,6 +442,99 @@ async fn get_entrypoints_with_issues(
.cell())
}

#[napi]
pub async fn project_entrypoints(
#[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
) -> napi::Result<TurbopackResult<NapiEntrypoints>> {
let turbo_tasks = project.turbo_tasks.clone();
let container = project.container;

let EntrypointsWithIssues {
entrypoints,
issues,
diagnostics,
} = &*get_entrypoints_with_issues(container)
.strongly_consistent()
.await?;

let issues_result = issues
.iter()
.map(|issue| NapiIssue::from(&**issue))
.collect();
let diagnostics_result = diagnostics
.iter()
.map(|d| NapiDiagnostic::from(d))
.collect();

let (
routes,
middleware,
instrumentation,
pages_document_endpoint,
pages_app_endpoint,
pages_error_endpoint,
) = turbo_tasks
.run_once(async move {
let routes = entrypoints
.routes
.iter()
.map(|(pathname, &route)| {
NapiRoute::from_route(pathname.clone(), route, &turbo_tasks)
})
.collect::<Vec<_>>();
let middleware = entrypoints
.middleware
.as_ref()
.map(|m| NapiMiddleware::from_middleware(m, &turbo_tasks))
.transpose()?;
let instrumentation = entrypoints
.instrumentation
.as_ref()
.map(|m| NapiInstrumentation::from_instrumentation(m, &turbo_tasks))
.transpose()?;

let pages_document_endpoint = External::new(ExternalEndpoint(VcArc::new(
turbo_tasks.clone(),
entrypoints.pages_document_endpoint,
)));

let pages_app_endpoint = External::new(ExternalEndpoint(VcArc::new(
turbo_tasks.clone(),
entrypoints.pages_app_endpoint,
)));

let pages_error_endpoint = External::new(ExternalEndpoint(VcArc::new(
turbo_tasks.clone(),
entrypoints.pages_error_endpoint,
)));

Ok((
routes,
middleware,
instrumentation,
pages_document_endpoint,
pages_app_endpoint,
pages_error_endpoint,
))
})
.await
.map_err(|e| napi::Error::from_reason(PrettyPrintError(&e).to_string()))?;

let turbopack_result = TurbopackResult {
result: NapiEntrypoints {
routes,
middleware,
instrumentation,
pages_document_endpoint,
pages_app_endpoint,
pages_error_endpoint,
},
issues: issues_result,
diagnostics: diagnostics_result,
};
Ok(turbopack_result)
}

#[napi(ts_return_type = "{ __napiType: \"RootTask\" }")]
pub fn project_entrypoints_subscribe(
#[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
"lru-cache": "5.1.1",
"mini-css-extract-plugin": "2.4.3",
"msw": "1.3.0",
"nanoid": "3.1.32",
"nanoid": "3.1.31",
"native-url": "0.3.4",
"neo-async": "2.6.1",
"node-html-parser": "5.3.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ export default async function build(
const project = await bindings.turbo.createProject({
projectPath: dir,
rootPath: config.experimental.outputFileTracingRoot || dir,
nextConfig: config.nextConfig,
nextConfig: config,
jsConfig: await getTurbopackJsConfig(dir, config),
watch: false,
env: process.env as Record<string, string>,
Expand All @@ -1335,8 +1335,8 @@ export default async function build(
}),
})

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const entrypointsSubscription = project.entrypointsSubscribe()
const entrypoints = await project.entrypoints()
console.log({ entrypoints })
// for await (const entrypoints of entrypointsSubscription) {
// }
throw new Error("next build doesn't support turbopack yet")
Expand Down
5 changes: 5 additions & 0 deletions packages/next/src/build/swc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ export interface UpdateInfo {

export interface Project {
update(options: Partial<ProjectOptions>): Promise<void>
entrypoints(): Promise<TurbopackResult<Entrypoints>>
entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<Entrypoints>>
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>
hmrIdentifiersSubscribe(): AsyncIterableIterator<
Expand Down Expand Up @@ -841,6 +842,10 @@ function bindingToApi(binding: any, _wasm: boolean) {
)
}

entrypoints() {
return binding.projectEntrypoints(this._nativeProject)
}

entrypointsSubscribe() {
type NapiEndpoint = { __napiType: 'Endpoint' }

Expand Down
12 changes: 7 additions & 5 deletions packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ export async function createHotReloaderTurbopack(
}),
})
const entrypointsSubscription = project.entrypointsSubscribe()
const currentEntrypoints: CurrentEntrypoints = new Map()
const changeSubscriptions: Map<
string,
Promise<AsyncIterator<any>>
> = new Map()

let prevMiddleware: boolean | undefined = undefined

const globalEntrypoints: GlobalEntrypoints = {
Expand Down Expand Up @@ -295,6 +291,10 @@ export async function createHotReloaderTurbopack(
> = new Map()

const clients = new Set<ws>()
const changeSubscriptions: Map<
string,
Promise<AsyncIterator<any>>
> = new Map()

const changeSubscription: ChangeSubscription = async (
page,
Expand Down Expand Up @@ -374,6 +374,8 @@ export async function createHotReloaderTurbopack(
subscription?.return!()
}

const currentEntrypoints: CurrentEntrypoints = new Map()

try {
async function handleEntrypointsSubscription() {
for await (const entrypoints of entrypointsSubscription) {
Expand Down
35 changes: 15 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading