Skip to content

Commit 2131862

Browse files
committed
Fix for NextJS 16
1 parent 0a385ac commit 2131862

File tree

4 files changed

+36
-42
lines changed

4 files changed

+36
-42
lines changed

.github/workflows/on-push.yml

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,21 @@ name: On Push
22
on: [push]
33
jobs:
44
build:
5-
name: Building
5+
name: Build & Test
66
runs-on: Linux
77
steps:
88
- name: Checking out repository
9-
uses: actions/checkout@v3
9+
uses: actions/checkout@v4
1010
- name: "Setup Node"
11-
uses: actions/setup-node@v3
11+
uses: actions/setup-node@v4
1212
with:
13-
node-version: '16'
13+
node-version: '22'
1414
cache: 'npm'
1515
- name: Installing
16-
run: npm install -save --save-dev
16+
run: npm install
1717
- name: Building
1818
run: npm run build
19-
- name: Done
20-
run: exit 0
21-
22-
testing:
23-
name: Testing
24-
needs: build
25-
runs-on: Linux
26-
steps:
27-
- name: "Setup Node"
28-
uses: actions/setup-node@v3
29-
with:
30-
node-version: '16'
31-
cache: 'npm'
32-
- name: Installing
33-
run: npm install -save --save-dev
34-
- name: Running linter
19+
- name: Linting
3520
run: npm run lint
36-
- name: Running tests
37-
run: npm run test
38-
- name: Done
39-
run: exit 0
21+
- name: Testing
22+
run: npm run test

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![GitHub package.json version](https://img.shields.io/github/package-json/v/LupCode/node-lup-root)
22
![npm bundle size](https://img.shields.io/bundlephobia/min/lup-root)
3-
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/LupCode/node-lup-root/On%20Push)
3+
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/LupCode/node-lup-root/on-push.yml?branch=main)
44
![NPM](https://img.shields.io/npm/l/lup-root)
55

66
# lup-root

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lup-root",
3-
"version": "1.3.10",
3+
"version": "1.3.11",
44
"description": "Determines absolute path to project root and main file",
55
"files": [
66
"lib/**/*"

src/index.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
11
let _MAIN = __filename.replace(/\\/g, '/'); // '\' -> '/'
22
let _ROOT = __dirname.replace(/\\/g, '/'); // '\' -> '/'
33

4-
const COMMON_BUILD_DIRECTORIES = ['/bin', '/.bin', '/build', '/out', '/target'];
4+
const COMMON_BUILD_DIRECTORIES = ['/bin', '/.bin', '/build', '/dist', '/lib', '/out', '/target'];
55

66
const originalStackTraceLimit = Error.stackTraceLimit;
77
Error.stackTraceLimit = Infinity;
88
try {
99
throw new Error();
1010
} catch (ex: any) {
1111
const lines = ex.stack.toString().split('\n');
12+
let found = false;
1213

13-
for (let i = lines.length - 1; i >= 0; i--) {
14+
for (let i = lines.length - 1; i >= 0 && !found; i--) {
1415
const line = lines[i].trim();
1516
let start = 0;
16-
let found = false;
17-
1817
do {
1918
start = line.indexOf('(', start);
2019
if (start < 0) break;
2120
start++;
2221
let end = start;
2322

24-
// find closing bracket
23+
// find closing bracket
2524
let countOpening = 1;
2625
do {
2726
const idx1 = line.indexOf('(', end);
2827
const idx2 = line.indexOf(')', end);
29-
if(idx1 < 0 && idx2 < 0){ countOpening = -1; break; }
28+
if (idx1 < 0 && idx2 < 0) {
29+
countOpening = -1;
30+
break;
31+
}
3032

31-
if(idx1 >= 0 && idx1 < idx2){
33+
if (idx1 >= 0 && idx1 < idx2) {
3234
// another opening bracket found
3335
countOpening++;
3436
end = idx1 + 1;
35-
} else { // closing bracket found
37+
} else {
38+
// closing bracket found
3639
countOpening--;
3740
end = idx2 + (countOpening === 0 ? 0 : 1);
3841
}
39-
} while(countOpening > 0);
40-
if(countOpening < 0) break;
42+
} while (countOpening > 0);
43+
if (countOpening < 0) break;
4144

4245
let path = line.substring(start, end).trim().replace(/\\/g, '/'); // '\' -> '/'
4346
start = end + 1;
@@ -47,7 +50,7 @@ try {
4750
path.startsWith('node:') ||
4851
path.startsWith('webpack-internal:') ||
4952
path.lastIndexOf('/webpack-runtime.') >= 0 ||
50-
path.lastIndexOf('/next/dist') >= 0 ||
53+
path.lastIndexOf('/next/dist') >= 0 ||
5154
path.startsWith('index ')
5255
)
5356
continue;
@@ -59,7 +62,17 @@ try {
5962
path = path.substring(0, end);
6063
}
6164

62-
if (path === _MAIN && path.lastIndexOf('/.next/server') < 0) break;
65+
// if (path === _MAIN && path.lastIndexOf('/.next/server') < 0) break;
66+
67+
// next middleware (special case)
68+
end = path.lastIndexOf('/.next/dev/server/');
69+
if (end >= 0) {
70+
const fileName = _MAIN.substring(_ROOT.length + 1);
71+
_ROOT = path.substring(0, end);
72+
_MAIN = _ROOT + (!_ROOT.endsWith('/') ? '/' : '') + fileName.substring(fileName.startsWith('/') ? 1 : 0);
73+
found = true;
74+
break;
75+
}
6376

6477
_MAIN = path;
6578
end = path.lastIndexOf('/node_modules/');
@@ -77,9 +90,7 @@ try {
7790
}
7891

7992
found = true;
80-
} while(!found);
81-
82-
if(found) break;
93+
} while (!found);
8394
}
8495
}
8596
Error.stackTraceLimit = originalStackTraceLimit;

0 commit comments

Comments
 (0)