@netlify/dev 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.cjs +148 -0
- package/dist/main.d.cts +6 -0
- package/dist/main.d.ts +6 -0
- package/dist/main.js +113 -0
- package/package.json +59 -0
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/main.ts
|
|
31
|
+
var main_exports = {};
|
|
32
|
+
__export(main_exports, {
|
|
33
|
+
handle: () => handle
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(main_exports);
|
|
36
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
37
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
38
|
+
var import_dev = require("@netlify/functions/dev");
|
|
39
|
+
var import_redirects = require("@netlify/redirects");
|
|
40
|
+
var import_static = require("@netlify/static");
|
|
41
|
+
|
|
42
|
+
// src/lib/config.ts
|
|
43
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
44
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
45
|
+
var import_config = require("@netlify/config");
|
|
46
|
+
var import_dev_utils = require("@netlify/dev-utils");
|
|
47
|
+
|
|
48
|
+
// src/lib/fs.ts
|
|
49
|
+
var import_node_fs = require("fs");
|
|
50
|
+
var isDirectory = async (path3) => {
|
|
51
|
+
try {
|
|
52
|
+
const stat = await import_node_fs.promises.stat(path3);
|
|
53
|
+
return stat.isDirectory();
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
var isFile = async (path3) => {
|
|
59
|
+
try {
|
|
60
|
+
const stat = await import_node_fs.promises.stat(path3);
|
|
61
|
+
return stat.isFile();
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/lib/config.ts
|
|
68
|
+
var getConfig = async ({
|
|
69
|
+
projectRoot
|
|
70
|
+
}) => {
|
|
71
|
+
const token = await (0, import_dev_utils.getAPIToken)();
|
|
72
|
+
const state = new import_dev_utils.LocalState(projectRoot);
|
|
73
|
+
const siteID = state.get("siteId");
|
|
74
|
+
const configFilePath = import_node_path.default.resolve(projectRoot, "netlify.toml");
|
|
75
|
+
const configFileExists = await isFile(configFilePath);
|
|
76
|
+
const config = await (0, import_config.resolveConfig)({
|
|
77
|
+
config: configFileExists ? configFilePath : void 0,
|
|
78
|
+
repositoryRoot: projectRoot,
|
|
79
|
+
cwd: import_node_process.default.cwd(),
|
|
80
|
+
context: "dev",
|
|
81
|
+
siteId: siteID,
|
|
82
|
+
token,
|
|
83
|
+
mode: "cli",
|
|
84
|
+
offline: !siteID
|
|
85
|
+
});
|
|
86
|
+
return { config, siteID };
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/main.ts
|
|
90
|
+
var notFoundHandler = async () => new Response("Not found", { status: 404 });
|
|
91
|
+
var handle = async (request, options) => {
|
|
92
|
+
const { projectRoot = import_node_process2.default.cwd() } = options ?? {};
|
|
93
|
+
const { config, siteID } = await getConfig({ projectRoot }) ?? {};
|
|
94
|
+
const userFunctionsPath = config?.config.functionsDirectory ?? import_node_path2.default.join(projectRoot, "netlify/functions");
|
|
95
|
+
const userFunctionsPathExists = await isDirectory(userFunctionsPath);
|
|
96
|
+
const functions = new import_dev.FunctionsHandler({
|
|
97
|
+
config,
|
|
98
|
+
destPath: import_node_path2.default.join(projectRoot, ".netlify", "functions-serve"),
|
|
99
|
+
projectRoot,
|
|
100
|
+
settings: {},
|
|
101
|
+
siteId: siteID,
|
|
102
|
+
timeouts: {},
|
|
103
|
+
userFunctionsPath: userFunctionsPathExists ? userFunctionsPath : void 0
|
|
104
|
+
});
|
|
105
|
+
const redirects = new import_redirects.RedirectsHandler({
|
|
106
|
+
configPath: config?.configPath,
|
|
107
|
+
configRedirects: config?.config.redirects,
|
|
108
|
+
jwtRoleClaim: "",
|
|
109
|
+
jwtSecret: "",
|
|
110
|
+
notFoundHandler,
|
|
111
|
+
projectDir: projectRoot
|
|
112
|
+
});
|
|
113
|
+
const staticFiles = new import_static.StaticHandler({
|
|
114
|
+
directory: config?.config.build.publish ?? projectRoot
|
|
115
|
+
});
|
|
116
|
+
const functionMatch = await functions.match(request);
|
|
117
|
+
if (functionMatch) {
|
|
118
|
+
if (functionMatch.preferStatic) {
|
|
119
|
+
const staticMatch2 = await staticFiles.match(request);
|
|
120
|
+
if (staticMatch2) {
|
|
121
|
+
return staticMatch2.handle();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return functionMatch.handle(request);
|
|
125
|
+
}
|
|
126
|
+
const redirectMatch = await redirects.match(request);
|
|
127
|
+
if (redirectMatch) {
|
|
128
|
+
const functionMatch2 = await functions.match(new Request(redirectMatch.target));
|
|
129
|
+
if (functionMatch2 && !functionMatch2.preferStatic) {
|
|
130
|
+
return functionMatch2.handle(request);
|
|
131
|
+
}
|
|
132
|
+
const response = await redirects.handle(request, redirectMatch, async (maybeStaticFile) => {
|
|
133
|
+
const staticMatch2 = await staticFiles.match(maybeStaticFile);
|
|
134
|
+
return staticMatch2?.handle;
|
|
135
|
+
});
|
|
136
|
+
if (response) {
|
|
137
|
+
return response;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const staticMatch = await staticFiles.match(request);
|
|
141
|
+
if (staticMatch) {
|
|
142
|
+
return staticMatch.handle();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
+
0 && (module.exports = {
|
|
147
|
+
handle
|
|
148
|
+
});
|
package/dist/main.d.cts
ADDED
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/main.ts
|
|
2
|
+
import path2 from "node:path";
|
|
3
|
+
import process2 from "node:process";
|
|
4
|
+
import { FunctionsHandler } from "@netlify/functions/dev";
|
|
5
|
+
import { RedirectsHandler } from "@netlify/redirects";
|
|
6
|
+
import { StaticHandler } from "@netlify/static";
|
|
7
|
+
|
|
8
|
+
// src/lib/config.ts
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import process from "node:process";
|
|
11
|
+
import { resolveConfig } from "@netlify/config";
|
|
12
|
+
import { getAPIToken, LocalState } from "@netlify/dev-utils";
|
|
13
|
+
|
|
14
|
+
// src/lib/fs.ts
|
|
15
|
+
import { promises as fs } from "node:fs";
|
|
16
|
+
var isDirectory = async (path3) => {
|
|
17
|
+
try {
|
|
18
|
+
const stat = await fs.stat(path3);
|
|
19
|
+
return stat.isDirectory();
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
var isFile = async (path3) => {
|
|
25
|
+
try {
|
|
26
|
+
const stat = await fs.stat(path3);
|
|
27
|
+
return stat.isFile();
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/lib/config.ts
|
|
34
|
+
var getConfig = async ({
|
|
35
|
+
projectRoot
|
|
36
|
+
}) => {
|
|
37
|
+
const token = await getAPIToken();
|
|
38
|
+
const state = new LocalState(projectRoot);
|
|
39
|
+
const siteID = state.get("siteId");
|
|
40
|
+
const configFilePath = path.resolve(projectRoot, "netlify.toml");
|
|
41
|
+
const configFileExists = await isFile(configFilePath);
|
|
42
|
+
const config = await resolveConfig({
|
|
43
|
+
config: configFileExists ? configFilePath : void 0,
|
|
44
|
+
repositoryRoot: projectRoot,
|
|
45
|
+
cwd: process.cwd(),
|
|
46
|
+
context: "dev",
|
|
47
|
+
siteId: siteID,
|
|
48
|
+
token,
|
|
49
|
+
mode: "cli",
|
|
50
|
+
offline: !siteID
|
|
51
|
+
});
|
|
52
|
+
return { config, siteID };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/main.ts
|
|
56
|
+
var notFoundHandler = async () => new Response("Not found", { status: 404 });
|
|
57
|
+
var handle = async (request, options) => {
|
|
58
|
+
const { projectRoot = process2.cwd() } = options ?? {};
|
|
59
|
+
const { config, siteID } = await getConfig({ projectRoot }) ?? {};
|
|
60
|
+
const userFunctionsPath = config?.config.functionsDirectory ?? path2.join(projectRoot, "netlify/functions");
|
|
61
|
+
const userFunctionsPathExists = await isDirectory(userFunctionsPath);
|
|
62
|
+
const functions = new FunctionsHandler({
|
|
63
|
+
config,
|
|
64
|
+
destPath: path2.join(projectRoot, ".netlify", "functions-serve"),
|
|
65
|
+
projectRoot,
|
|
66
|
+
settings: {},
|
|
67
|
+
siteId: siteID,
|
|
68
|
+
timeouts: {},
|
|
69
|
+
userFunctionsPath: userFunctionsPathExists ? userFunctionsPath : void 0
|
|
70
|
+
});
|
|
71
|
+
const redirects = new RedirectsHandler({
|
|
72
|
+
configPath: config?.configPath,
|
|
73
|
+
configRedirects: config?.config.redirects,
|
|
74
|
+
jwtRoleClaim: "",
|
|
75
|
+
jwtSecret: "",
|
|
76
|
+
notFoundHandler,
|
|
77
|
+
projectDir: projectRoot
|
|
78
|
+
});
|
|
79
|
+
const staticFiles = new StaticHandler({
|
|
80
|
+
directory: config?.config.build.publish ?? projectRoot
|
|
81
|
+
});
|
|
82
|
+
const functionMatch = await functions.match(request);
|
|
83
|
+
if (functionMatch) {
|
|
84
|
+
if (functionMatch.preferStatic) {
|
|
85
|
+
const staticMatch2 = await staticFiles.match(request);
|
|
86
|
+
if (staticMatch2) {
|
|
87
|
+
return staticMatch2.handle();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return functionMatch.handle(request);
|
|
91
|
+
}
|
|
92
|
+
const redirectMatch = await redirects.match(request);
|
|
93
|
+
if (redirectMatch) {
|
|
94
|
+
const functionMatch2 = await functions.match(new Request(redirectMatch.target));
|
|
95
|
+
if (functionMatch2 && !functionMatch2.preferStatic) {
|
|
96
|
+
return functionMatch2.handle(request);
|
|
97
|
+
}
|
|
98
|
+
const response = await redirects.handle(request, redirectMatch, async (maybeStaticFile) => {
|
|
99
|
+
const staticMatch2 = await staticFiles.match(maybeStaticFile);
|
|
100
|
+
return staticMatch2?.handle;
|
|
101
|
+
});
|
|
102
|
+
if (response) {
|
|
103
|
+
return response;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const staticMatch = await staticFiles.match(request);
|
|
107
|
+
if (staticMatch) {
|
|
108
|
+
return staticMatch.handle();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
export {
|
|
112
|
+
handle
|
|
113
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@netlify/dev",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Local development emulation for Netlify",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": "^14.16.0 || >=16.0.0"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/main.cjs",
|
|
10
|
+
"module": "./dist/main.js",
|
|
11
|
+
"types": "./dist/main.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/main.d.cts",
|
|
16
|
+
"default": "./dist/main.cjs"
|
|
17
|
+
},
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./dist/main.d.ts",
|
|
20
|
+
"default": "./dist/main.js"
|
|
21
|
+
},
|
|
22
|
+
"default": {
|
|
23
|
+
"types": "./dist/main.d.ts",
|
|
24
|
+
"default": "./dist/main.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/**/*"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup-node",
|
|
34
|
+
"prepack": "npm run build",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"test:dev": "vitest",
|
|
37
|
+
"test:ci": "npm run build && vitest run",
|
|
38
|
+
"dev": "tsup-node --watch"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [],
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"repository": "netlify/primitives",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/netlify/primitives/issues"
|
|
45
|
+
},
|
|
46
|
+
"author": "Netlify Inc.",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"tmp-promise": "^3.0.3",
|
|
49
|
+
"tsup": "^7.2.0",
|
|
50
|
+
"vitest": "^0.34.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@netlify/config": "^22.0.0",
|
|
54
|
+
"@netlify/dev-utils": "1.1.0",
|
|
55
|
+
"@netlify/functions": "3.1.0",
|
|
56
|
+
"@netlify/redirects": "1.1.0",
|
|
57
|
+
"@netlify/static": "1.1.0"
|
|
58
|
+
}
|
|
59
|
+
}
|