@ms-cloudpack/bundle-server 0.2.0 → 0.2.1
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/README.md +4 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/startBundleServer.d.ts +1 -7
- package/lib/startBundleServer.d.ts.map +1 -1
- package/lib/startBundleServer.js.map +1 -1
- package/lib/types/BundleServerContext.d.ts +7 -0
- package/lib/types/BundleServerContext.d.ts.map +1 -0
- package/lib/types/BundleServerContext.js +2 -0
- package/lib/types/BundleServerContext.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# @ms-cloudpack/bundle-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides a Bundle server for Cloudpack.
|
|
4
|
+
|
|
5
|
+
The bundle server handles package requests and returns bundled resources.
|
|
6
|
+
Resources are bundled on demand and cached locally and in the browser to avoid re-bundling on each request.
|
|
4
7
|
|
|
5
8
|
## Usage
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,YAAY,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { startBundleServer } from './startBundleServer.js';\nexport type { BundleServer } from './types/BundleServer.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { startBundleServer } from './startBundleServer.js';\nexport type { BundleServer } from './types/BundleServer.js';\nexport type { BundleServerContext } from './types/BundleServerContext.js';\n"]}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import type { ApiServer, Context } from '@ms-cloudpack/api-server';
|
|
2
1
|
import type { BundleServer } from './types/BundleServer.js';
|
|
3
|
-
type BundleServerContext
|
|
4
|
-
apiServer: ApiServer;
|
|
5
|
-
} & {
|
|
6
|
-
disableCache: boolean;
|
|
7
|
-
};
|
|
2
|
+
import type { BundleServerContext } from './types/BundleServerContext.js';
|
|
8
3
|
/**
|
|
9
4
|
* The bundle server handles package requests and returns bundled resources.
|
|
10
5
|
* Resources are bundled on demand and cached locally to avoid re-bundling
|
|
@@ -13,5 +8,4 @@ type BundleServerContext = Pick<Context, 'bus' | 'taskRunner' | 'watcher' | 'tel
|
|
|
13
8
|
export declare function startBundleServer(options: {
|
|
14
9
|
context: BundleServerContext;
|
|
15
10
|
}): Promise<BundleServer>;
|
|
16
|
-
export {};
|
|
17
11
|
//# sourceMappingURL=startBundleServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startBundleServer.d.ts","sourceRoot":"","sources":["../src/startBundleServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"startBundleServer.d.ts","sourceRoot":"","sources":["../src/startBundleServer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAI1E;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAAE,OAAO,EAAE,mBAAmB,CAAA;CAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAwBxG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../src/startBundleServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../src/startBundleServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA6C,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAyC;IAC/E,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,MAAM,gBAAgB,CAAC;QAClD,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;QACnC,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM;QAClC,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK;QACnC,aAAa,EAAE,CAAC,GAAY,EAAE,EAAE;YAC9B,iCAAiC;YACjC,GAAG,CAAC,GAAG,CAA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AC,CAAC;IAE1C,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { createExpressApp, type Express, type Request, type Response } from '@ms-cloudpack/create-express-app';\nimport { isExternalPackage, findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\nimport type { BundleServer } from './types/BundleServer.js';\nimport type { BundleServerContext } from './types/BundleServerContext.js';\nimport { parseRequestInfo } from '@ms-cloudpack/api-server';\nimport { ensurePackageBundled } from '@ms-cloudpack/api-server/apis';\n\n/**\n * The bundle server handles package requests and returns bundled resources.\n * Resources are bundled on demand and cached locally to avoid re-bundling\n * on each request.\n */\nexport async function startBundleServer(options: { context: BundleServerContext }): Promise<BundleServer> {\n const { context } = options;\n const { session } = context;\n const { config } = session;\n const { port, close, url } = await createExpressApp({\n portRange: [5500, 5501, 5502, 5503],\n hostname: config.devServer?.domain,\n sslOptions: config.devServer?.https,\n setupCallback: (app: Express) => {\n // Set up the express app routes.\n app.get('*', (req, res) => {\n handleRequest({ req, res }, context).catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error bundling: ${err}`);\n });\n });\n },\n });\n\n return {\n close,\n port,\n url,\n };\n}\n\nasync function handleRequest(\n options: {\n req: Request;\n res: Response;\n },\n context: BundleServerContext,\n) {\n const { req, res } = options;\n const { session, packageHashes, disableCache } = context;\n const { resolveMap, config } = session;\n const { features = {} } = config;\n const requestPath = slash(req.path.substring(1));\n const force = req.query.force !== undefined;\n const { packageName, version, hash, bundled, filePath } = parseRequestInfo(requestPath);\n const packageEntry = findResolveMapEntry({ packageName, version, resolveMap });\n\n if (!packageEntry) {\n // If the package is missing, invalid arguments.\n console.debug(`Response (404): Unrecognized package \"${packageName}\"`);\n res.status(404).send(`Unrecognized package \"${packageName}\".`);\n return;\n }\n\n console.debug(`Request: \"${packageName}@${version}${filePath}\"`);\n\n // If the package is missing, invalid arguments.\n if (!requestPath || !packageName) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Requests must be in the format \"/{packageName}@{version}/{type}/path/file.ext\".`);\n return;\n }\n\n // If the version is missing, redirect to the primary version.\n if (!version) {\n res.redirect(`/${packageName}@${packageEntry.version}${filePath}`);\n return;\n }\n\n // If we are accessing a non-bundled asset, return the file directly.\n if (!bundled) {\n const fullPath = path.join(packageEntry.path, filePath);\n\n if (fullPath.length < packageEntry.path.length) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Invalid file path.`);\n } else {\n console.debug(`Unbundled response returning: \"${packageName}@${version}${filePath}\"`);\n // If the package is external, set cache headers.\n if (isExternalPackage(packageEntry.path)) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(packageEntry.path, filePath));\n }\n return;\n }\n\n console.debug(`Trying to bundle \"${packageName}@${version}\"`);\n const { result } = await ensurePackageBundled({\n input: {\n name: packageName,\n version,\n shouldForce: force,\n shouldRerun: force,\n shouldWatch: true, // This will only watch the package if it is internal.\n disableCache,\n },\n ctx: context,\n });\n\n if (result.errors?.length) {\n res.status(500).type('json').send(result);\n return;\n }\n\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (\n result.isExternal ||\n (features.hashPackages &&\n hash !== 'pending' &&\n hash === (await packageHashes.get({ packagePath: packageEntry.path, isSourceHashingEnabled: true })))\n ) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n // The below header is need to be able to track the browser cache hit ratio.\n res.setHeader('Timing-Allow-Origin', '*');\n\n res.sendFile(path.join(result.outputPath, filePath));\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiServer, Context } from '@ms-cloudpack/api-server';
|
|
2
|
+
export type BundleServerContext = Pick<Context, 'bus' | 'taskRunner' | 'watcher' | 'telemetryClient' | 'packageImportPaths' | 'packages' | 'reporter' | 'session' | 'packageHashes'> & {
|
|
3
|
+
apiServer: ApiServer;
|
|
4
|
+
} & {
|
|
5
|
+
disableCache: boolean;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=BundleServerContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BundleServerContext.d.ts","sourceRoot":"","sources":["../../src/types/BundleServerContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnE,MAAM,MAAM,mBAAmB,GAAG,IAAI,CACpC,OAAO,EACL,KAAK,GACL,YAAY,GACZ,SAAS,GACT,iBAAiB,GACjB,oBAAoB,GACpB,UAAU,GACV,UAAU,GACV,SAAS,GACT,eAAe,CAClB,GAAG;IACF,SAAS,EAAE,SAAS,CAAC;CACtB,GAAG;IACF,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BundleServerContext.js","sourceRoot":"","sources":["../../src/types/BundleServerContext.ts"],"names":[],"mappings":"","sourcesContent":["import type { ApiServer, Context } from '@ms-cloudpack/api-server';\n\nexport type BundleServerContext = Pick<\n Context,\n | 'bus'\n | 'taskRunner'\n | 'watcher'\n | 'telemetryClient'\n | 'packageImportPaths'\n | 'packages'\n | 'reporter'\n | 'session'\n | 'packageHashes'\n> & {\n apiServer: ApiServer;\n} & {\n disableCache: boolean;\n};\n"]}
|