-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip #1817 webpack specific require.context()
- Loading branch information
1 parent
7faad91
commit 27bdc9d
Showing
176 changed files
with
699 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { | ||
Request, | ||
Response, | ||
} from '/types'; | ||
|
||
|
||
import { | ||
getLauncherPath, | ||
getLocales | ||
} from '/lib/xp/admin'; | ||
// @ts-expect-error Cannot find module '/lib/mustache' or its corresponding type declarations.ts(2307) | ||
import mustache from '/lib/mustache'; | ||
// @ts-expect-error Cannot find module '/lib/router' or its corresponding type declarations.ts(2307) | ||
import Router from '/lib/router'; | ||
import { | ||
assetUrl, | ||
serviceUrl | ||
} from '/lib/xp/portal'; | ||
import { localize } from '/lib/xp/i18n'; | ||
import { immutableGetter, getAdminUrl } from '/lib/urlHelper'; | ||
import { | ||
FILEPATH_MANIFEST_CJS, | ||
FILEPATH_MANIFEST_NODE_MODULES, | ||
GETTER_ROOT, | ||
} from '/constants'; | ||
|
||
const TOOL_NAME = 'main'; | ||
const VIEW = resolve('./main.html'); | ||
|
||
const router = Router(); | ||
|
||
router.all(`/${GETTER_ROOT}/{path:.+}`, (r: Request) => { | ||
return immutableGetter(r); | ||
}); | ||
|
||
function get(_request: Request): Response { | ||
const params = { | ||
appUsersBundleUrl: getAdminUrl({ | ||
path: 'main.js' | ||
}, TOOL_NAME), | ||
assetsUri: assetUrl({path: ''}), | ||
appName: localize({ | ||
key: 'admin.tool.displayName', | ||
bundles: ['i18n/phrases'], | ||
locale: getLocales() | ||
}), | ||
configServiceUrl: serviceUrl({service: 'config'}), | ||
jqueryUrl: getAdminUrl({ | ||
manifestPath: FILEPATH_MANIFEST_NODE_MODULES, | ||
path: 'jquery/dist/jquery.min.js', | ||
}, TOOL_NAME), | ||
jqueryUiUrl: getAdminUrl({ | ||
manifestPath: FILEPATH_MANIFEST_NODE_MODULES, | ||
path: 'jquery-ui/dist/jquery-ui.min.js', | ||
}, TOOL_NAME), | ||
launcherPath: getLauncherPath(), | ||
}; | ||
|
||
return { | ||
contentType: 'text/html', | ||
body: mustache.render(VIEW, params), | ||
headers: { | ||
'content-security-policy': 'default-src \'self\'; script-src \'self\' \'unsafe-eval\'; style-src \'self\' \'unsafe-inline\'; object-src \'none\'; img-src \'self\' data:' | ||
} | ||
}; | ||
} | ||
|
||
router.get('', (r: Request) => get(r)); // Default admin tool path | ||
router.get('/', (r: Request) => get(r)); // Just in case someone adds a slash on the end | ||
|
||
export const all = (r: Request) => router.dispatch(r); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const GETTER_ROOT = 'static'; | ||
export const FILEPATH_MANIFEST_CJS = `/${GETTER_ROOT}/manifest.cjs.json`; | ||
// export const FILEPATH_MANIFEST_ESM = `/${GETTER_ROOT}/manifest.esm.json`; | ||
export const FILEPATH_MANIFEST_NODE_MODULES = `/${GETTER_ROOT}/node_modules-manifest.json`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
getResource, | ||
readText | ||
} from '/lib/xp/io'; | ||
|
||
|
||
export function readResource(filename: string) { | ||
const resource = getResource(filename); | ||
if (!resource || !resource.exists()) { | ||
throw new Error(`Empty or not found: ${filename}`); | ||
} | ||
let content: string; | ||
try { | ||
content = readText(resource.getStream()); | ||
// log.debug('readResource: filename:%s content:%s', filename, content); | ||
} catch (e) { | ||
log.error(e.message); | ||
throw new Error(`Couldn't read resource: ${filename}`); | ||
} | ||
return content; | ||
} | ||
|
||
function jsonParseResource(filename: string) { | ||
const content = readResource(filename); | ||
let obj: object; | ||
try { | ||
obj = JSON.parse(content); | ||
log.debug('jsonParseResource obj:%s', JSON.stringify(obj, null, 4)); | ||
} catch (e) { | ||
log.error(e.message); | ||
log.info("Content dump from '" + filename + "':\n" + content); | ||
throw new Error(`couldn't parse as JSON content of resource: ${filename}`); | ||
} | ||
return obj; | ||
} | ||
|
||
|
||
export default jsonParseResource; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare const Java: { | ||
type: (_classPath: string) => { | ||
get: () => string | ||
} | ||
}; | ||
|
||
export const XP_RUN_MODE = `${Java.type('com.enonic.xp.server.RunMode').get()}`; // PROD || DEV | ||
export const IS_DEV_MODE = XP_RUN_MODE === 'DEV'; | ||
export const IS_PROD_MODE = XP_RUN_MODE === 'PROD'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import type {Request, Response} from '/types'; | ||
|
||
// @ts-expect-error TS2307: Cannot find module '/lib/enonic/static' or its corresponding type declarations. | ||
import { buildGetter } from '/lib/enonic/static'; | ||
import { getToolUrl } from '/lib/xp/admin'; | ||
import { | ||
FILEPATH_MANIFEST_CJS, | ||
FILEPATH_MANIFEST_NODE_MODULES, | ||
GETTER_ROOT | ||
} from '../constants'; | ||
import ioResource from './ioResource'; | ||
import { IS_DEV_MODE } from './runMode'; | ||
|
||
|
||
interface UrlPostfixParams { | ||
manifestPath?: string | ||
path: string, | ||
}; | ||
|
||
type UrlParams = UrlPostfixParams & {urlPrefix: string}; | ||
|
||
|
||
const manifests = { | ||
[FILEPATH_MANIFEST_CJS]: ioResource(FILEPATH_MANIFEST_CJS), | ||
// [FILEPATH_MANIFEST_ESM]: ioResource(FILEPATH_MANIFEST_ESM), | ||
[FILEPATH_MANIFEST_NODE_MODULES]: ioResource(FILEPATH_MANIFEST_NODE_MODULES), | ||
} | ||
|
||
const getImmutableUrl = ({ | ||
manifestPath = FILEPATH_MANIFEST_CJS, | ||
path, | ||
urlPrefix | ||
}: UrlParams) => { | ||
if (IS_DEV_MODE) { | ||
manifests[manifestPath] = ioResource(manifestPath); | ||
} | ||
|
||
return `${urlPrefix}/${GETTER_ROOT}/${manifests[manifestPath][path]}`; | ||
} | ||
|
||
export const getAdminUrl = ({ | ||
manifestPath = FILEPATH_MANIFEST_CJS, | ||
path, | ||
}: UrlPostfixParams, tool: string) => { | ||
const urlPrefix = getToolUrl(app.name, tool); | ||
|
||
return getImmutableUrl({ | ||
manifestPath, | ||
path, | ||
urlPrefix | ||
}); | ||
} | ||
|
||
export const immutableGetter = buildGetter({ | ||
etag: false, // default is true in production and false in development | ||
getCleanPath: (request: Request) => { | ||
log.debug('request:%s', JSON.stringify(request, null, 4)); | ||
log.debug('contextPath:%s', request.contextPath); | ||
log.debug('rawPath:%s', request.rawPath); | ||
|
||
const prefix = request.contextPath; | ||
let cleanPath = prefix ? request.rawPath.substring(prefix.length) : request.rawPath; | ||
cleanPath = cleanPath.replace(`${GETTER_ROOT}/`, ''); | ||
|
||
log.debug('cleanPath:%s', cleanPath); | ||
|
||
return cleanPath; | ||
}, | ||
root: GETTER_ROOT | ||
}) as (_request: Request) => Response; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"esModuleInterop": true, // Needed for the 'q' npm module | ||
"module": "commonjs", | ||
"lib": [ | ||
"DOM", | ||
"ES2020", | ||
"ES2015.Promise" | ||
], | ||
"moduleResolution": "node", | ||
"paths": {}, | ||
"rootDir": ".", | ||
"skipLibCheck": true, | ||
"target": "es5", // Modern browsers | ||
"types": [ | ||
"hasher", | ||
"q", | ||
"nanoid", | ||
"owasp-password-strength-test" | ||
], | ||
}, | ||
"include": [ | ||
"./**/*.ts" | ||
], | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
// This file is used by your code editor and the build system, | ||
// for TypeScript files except for those under ./assets/. | ||
// https://www.typescriptlang.org/tsconfig | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"lib": [ | ||
"ES5" | ||
], | ||
"paths": { | ||
"/lib/xp/*": ["../../../node_modules/@enonic-types/lib-*"], | ||
"/*": ["./*"] | ||
}, | ||
"rootDir": ".", | ||
"skipLibCheck": true, | ||
// "typeRoots": [ | ||
// "node_modules/@types", | ||
// "node_modules/@enonic-types" | ||
// ], | ||
"types": [ | ||
"@enonic-types/global" | ||
// "global" // When typeRoots is set the prefix @enonic-types/ must be removed. | ||
] | ||
}, | ||
"exclude": [ | ||
"./assets/**/*", | ||
], | ||
"include": [ | ||
"./**/*.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface PageContributions { | ||
headBegin?: string[] | ||
headEnd?: string[] | ||
bodyBegin?: string[] | ||
bodyEnd?: string[] | ||
} |
Oops, something went wrong.