Initial boiler plate project

This commit is contained in:
2024-09-24 03:52:46 +00:00
parent 6120b2d6c3
commit 154b93e267
10034 changed files with 2079352 additions and 2 deletions

View File

@ -0,0 +1,130 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Shared between webpack 4 and 5:
function injectRefreshFunctions(compilation, Template) {
const hookVars = compilation.mainTemplate.hooks.localVars;
hookVars.tap('ReactFreshWebpackPlugin', (source) => Template.asString([
source,
'',
'// noop fns to prevent runtime errors during initialization',
'if (typeof self !== "undefined") {',
Template.indent('self.$RefreshReg$ = function () {};'),
Template.indent('self.$RefreshSig$ = function () {'),
Template.indent(Template.indent('return function (type) {')),
Template.indent(Template.indent(Template.indent('return type;'))),
Template.indent(Template.indent('};')),
Template.indent('};'),
'}',
]));
}
function webpack4(compiler) {
const { Template } = this;
// Webpack 4 does not have a method to handle interception of module
// execution.
// The closest thing we have to emulating this is mimicking the behavior of
// `strictModuleExceptionHandling` in `MainTemplate`:
// https://github.com/webpack/webpack/blob/4c644bf1f7cb067c748a52614500e0e2182b2700/lib/MainTemplate.js#L200
compiler.hooks.compilation.tap('ReactFreshWebpackPlugin', (compilation) => {
injectRefreshFunctions(compilation, Template);
const hookRequire = compilation.mainTemplate.hooks.require;
// @ts-ignore webpack 5 types compat
hookRequire.tap('ReactFreshWebpackPlugin', (source) => {
// Webpack 4 evaluates module code on the following line:
// ```
// modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
// ```
// https://github.com/webpack/webpack/blob/4c644bf1f7cb067c748a52614500e0e2182b2700/lib/MainTemplate.js#L200
const lines = source.split('\n');
// @ts-ignore webpack 5 types compat
const evalIndex = lines.findIndex((l) => l.includes('modules[moduleId].call('));
// Unable to find the module execution, that's OK:
if (evalIndex === -1) {
return source;
}
// Legacy CSS implementations will `eval` browser code in a Node.js
// context to extract CSS. For backwards compatibility, we need to check
// we're in a browser context before continuing.
return Template.asString([
...lines.slice(0, evalIndex),
`
var hasRefresh = typeof self !== "undefined" && !!self.$RefreshInterceptModuleExecution$;
var cleanup = hasRefresh
? self.$RefreshInterceptModuleExecution$(moduleId)
: function() {};
try {
`,
lines[evalIndex],
`
} finally {
cleanup();
}
`,
...lines.slice(evalIndex + 1),
]);
});
});
}
function webpack5(compiler) {
const { RuntimeGlobals, RuntimeModule, Template } = this;
class ReactRefreshRuntimeModule extends RuntimeModule {
constructor() {
super('react refresh', 5);
}
generate() {
const { runtimeTemplate } = this.compilation;
return Template.asString([
`if (${RuntimeGlobals.interceptModuleExecution}) {`,
`${RuntimeGlobals.interceptModuleExecution}.push(${runtimeTemplate.basicFunction('options', [
`${runtimeTemplate.supportsConst() ? 'const' : 'var'} originalFactory = options.factory;`,
`options.factory = ${runtimeTemplate.basicFunction('moduleObject, moduleExports, webpackRequire', [
// Legacy CSS implementations will `eval` browser code in a Node.js
// context to extract CSS. For backwards compatibility, we need to check
// we're in a browser context before continuing.
`${runtimeTemplate.supportsConst() ? 'const' : 'var'} hasRefresh = typeof self !== "undefined" && !!self.$RefreshInterceptModuleExecution$;`,
`${runtimeTemplate.supportsConst() ? 'const' : 'var'} cleanup = hasRefresh ? self.$RefreshInterceptModuleExecution$(moduleObject.id) : ${runtimeTemplate.supportsArrowFunction()
? '() => {}'
: 'function() {}'};`,
'try {',
Template.indent('originalFactory.call(this, moduleObject, moduleExports, webpackRequire);'),
'} finally {',
Template.indent(`cleanup();`),
'}',
])}`,
])})`,
'}',
]);
}
}
// @ts-ignore webpack 5 types compat
compiler.hooks.compilation.tap('ReactFreshWebpackPlugin', (compilation) => {
injectRefreshFunctions(compilation, Template);
compilation.hooks.additionalTreeRuntimeRequirements.tap('ReactFreshWebpackPlugin', (chunk) => {
compilation.addRuntimeModule(chunk, new ReactRefreshRuntimeModule());
});
});
}
class ReactFreshWebpackPlugin {
constructor({ version, RuntimeGlobals, RuntimeModule, Template } = require('webpack')) {
this.webpackMajorVersion = parseInt(version !== null && version !== void 0 ? version : '', 10);
this.RuntimeGlobals = RuntimeGlobals;
this.RuntimeModule = RuntimeModule;
this.Template = Template;
}
apply(compiler) {
switch (this.webpackMajorVersion) {
case 4: {
webpack4.call(this, compiler);
break;
}
case 5: {
webpack5.call(this, compiler);
break;
}
default: {
throw new Error(`ReactFreshWebpackPlugin does not support webpack v${this.webpackMajorVersion}.`);
}
}
}
}
exports.default = ReactFreshWebpackPlugin;
//# sourceMappingURL=ReactRefreshWebpackPlugin.js.map

View File

@ -0,0 +1,69 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// This function gets unwrapped into global scope, which is why we don't invert
// if-blocks. Also, you cannot use `return`.
function default_1() {
// Wrapped in an IIFE to avoid polluting the global scope
;
(function () {
var _a, _b;
// Legacy CSS implementations will `eval` browser code in a Node.js context
// to extract CSS. For backwards compatibility, we need to check we're in a
// browser context before continuing.
if (typeof self !== 'undefined' &&
// AMP / No-JS mode does not inject these helpers:
'$RefreshHelpers$' in self) {
// @ts-ignore __webpack_module__ is global
var currentExports = __webpack_module__.exports;
// @ts-ignore __webpack_module__ is global
var prevSignature = (_b = (_a = __webpack_module__.hot.data) === null || _a === void 0 ? void 0 : _a.prevSignature) !== null && _b !== void 0 ? _b : null;
// This cannot happen in MainTemplate because the exports mismatch between
// templating and execution.
self.$RefreshHelpers$.registerExportsForReactRefresh(currentExports, __webpack_module__.id);
// A module can be accepted automatically based on its exports, e.g. when
// it is a Refresh Boundary.
if (self.$RefreshHelpers$.isReactRefreshBoundary(currentExports)) {
// Save the previous exports signature on update so we can compare the boundary
// signatures. We avoid saving exports themselves since it causes memory leaks (https://github.com/vercel/next.js/pull/53797)
__webpack_module__.hot.dispose(function (data) {
data.prevSignature =
self.$RefreshHelpers$.getRefreshBoundarySignature(currentExports);
});
// Unconditionally accept an update to this module, we'll check if it's
// still a Refresh Boundary later.
// @ts-ignore importMeta is replaced in the loader
global.importMeta.webpackHot.accept();
// This field is set when the previous version of this module was a
// Refresh Boundary, letting us know we need to check for invalidation or
// enqueue an update.
if (prevSignature !== null) {
// A boundary can become ineligible if its exports are incompatible
// with the previous exports.
//
// For example, if you add/remove/change exports, we'll want to
// re-execute the importing modules, and force those components to
// re-render. Similarly, if you convert a class component to a
// function, we want to invalidate the boundary.
if (self.$RefreshHelpers$.shouldInvalidateReactRefreshBoundary(prevSignature, self.$RefreshHelpers$.getRefreshBoundarySignature(currentExports))) {
__webpack_module__.hot.invalidate();
}
else {
self.$RefreshHelpers$.scheduleUpdate();
}
}
}
else {
// Since we just executed the code for the module, it's possible that the
// new exports made it ineligible for being a boundary.
// We only care about the case when we were _previously_ a boundary,
// because we already accepted this update (accidental side effect).
var isNoLongerABoundary = prevSignature !== null;
if (isNoLongerABoundary) {
__webpack_module__.hot.invalidate();
}
}
}
})();
}
exports.default = default_1;
//# sourceMappingURL=ReactRefreshModule.runtime.js.map

View File

@ -0,0 +1,170 @@
"use strict";
/**
* MIT License
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// This file is copied from the Metro JavaScript bundler, with minor tweaks for
// webpack 4 compatibility.
//
// https://github.com/facebook/metro/blob/d6b9685c730d0d63577db40f41369157f28dfa3a/packages/metro/src/lib/polyfills/require.js
const runtime_1 = __importDefault(require("next/dist/compiled/react-refresh/runtime"));
function isSafeExport(key) {
return (key === '__esModule' ||
key === '__N_SSG' ||
key === '__N_SSP' ||
// TODO: remove this key from page config instead of allow listing it
key === 'config');
}
function registerExportsForReactRefresh(moduleExports, moduleID) {
runtime_1.default.register(moduleExports, moduleID + ' %exports%');
if (moduleExports == null || typeof moduleExports !== 'object') {
// Exit if we can't iterate over exports.
// (This is important for legacy environments.)
return;
}
for (var key in moduleExports) {
if (isSafeExport(key)) {
continue;
}
try {
var exportValue = moduleExports[key];
}
catch (_a) {
// This might fail due to circular dependencies
continue;
}
var typeID = moduleID + ' %exports% ' + key;
runtime_1.default.register(exportValue, typeID);
}
}
function getRefreshBoundarySignature(moduleExports) {
var signature = [];
signature.push(runtime_1.default.getFamilyByType(moduleExports));
if (moduleExports == null || typeof moduleExports !== 'object') {
// Exit if we can't iterate over exports.
// (This is important for legacy environments.)
return signature;
}
for (var key in moduleExports) {
if (isSafeExport(key)) {
continue;
}
try {
var exportValue = moduleExports[key];
}
catch (_a) {
// This might fail due to circular dependencies
continue;
}
signature.push(key);
signature.push(runtime_1.default.getFamilyByType(exportValue));
}
return signature;
}
function isReactRefreshBoundary(moduleExports) {
if (runtime_1.default.isLikelyComponentType(moduleExports)) {
return true;
}
if (moduleExports == null || typeof moduleExports !== 'object') {
// Exit if we can't iterate over exports.
return false;
}
var hasExports = false;
var areAllExportsComponents = true;
for (var key in moduleExports) {
hasExports = true;
if (isSafeExport(key)) {
continue;
}
try {
var exportValue = moduleExports[key];
}
catch (_a) {
// This might fail due to circular dependencies
return false;
}
if (!runtime_1.default.isLikelyComponentType(exportValue)) {
areAllExportsComponents = false;
}
}
return hasExports && areAllExportsComponents;
}
function shouldInvalidateReactRefreshBoundary(prevSignature, nextSignature) {
if (prevSignature.length !== nextSignature.length) {
return true;
}
for (var i = 0; i < nextSignature.length; i++) {
if (prevSignature[i] !== nextSignature[i]) {
return true;
}
}
return false;
}
var isUpdateScheduled = false;
// This function aggregates updates from multiple modules into a single React Refresh call.
function scheduleUpdate() {
if (isUpdateScheduled) {
return;
}
isUpdateScheduled = true;
function canApplyUpdate(status) {
return status === 'idle';
}
function applyUpdate() {
isUpdateScheduled = false;
try {
runtime_1.default.performReactRefresh();
}
catch (err) {
console.warn('Warning: Failed to re-render. We will retry on the next Fast Refresh event.\n' +
err);
}
}
if (canApplyUpdate(module.hot.status())) {
// Apply update on the next tick.
Promise.resolve().then(() => {
applyUpdate();
});
return;
}
const statusHandler = (status) => {
if (canApplyUpdate(status)) {
module.hot.removeStatusHandler(statusHandler);
applyUpdate();
}
};
// Apply update once the HMR runtime's status is idle.
module.hot.addStatusHandler(statusHandler);
}
// Needs to be compatible with IE11
exports.default = {
registerExportsForReactRefresh: registerExportsForReactRefresh,
isReactRefreshBoundary: isReactRefreshBoundary,
shouldInvalidateReactRefreshBoundary: shouldInvalidateReactRefreshBoundary,
getRefreshBoundarySignature: getRefreshBoundarySignature,
scheduleUpdate: scheduleUpdate,
};
//# sourceMappingURL=helpers.js.map

View File

@ -0,0 +1,21 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ReactRefreshModule_runtime_1 = __importDefault(require("./internal/ReactRefreshModule.runtime"));
let refreshModuleRuntime = ReactRefreshModule_runtime_1.default.toString();
refreshModuleRuntime = refreshModuleRuntime
.slice(refreshModuleRuntime.indexOf('{') + 1, refreshModuleRuntime.lastIndexOf('}'))
// Given that the import above executes the module we need to make sure it does not crash on `import.meta` not being allowed.
.replace('global.importMeta', 'import.meta');
let commonJsrefreshModuleRuntime = refreshModuleRuntime.replace('import.meta.webpackHot', 'module.hot');
const ReactRefreshLoader = function ReactRefreshLoader(source, inputSourceMap) {
this.callback(null, `${source}\n\n;${
// Account for commonjs not supporting `import.meta
this.resourcePath.endsWith('.cjs')
? commonJsrefreshModuleRuntime
: refreshModuleRuntime}`, inputSourceMap);
};
exports.default = ReactRefreshLoader;
//# sourceMappingURL=loader.js.map

View File

@ -0,0 +1,27 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const runtime_1 = __importDefault(require("next/dist/compiled/react-refresh/runtime"));
const helpers_1 = __importDefault(require("./internal/helpers"));
// Hook into ReactDOM initialization
runtime_1.default.injectIntoGlobalHook(self);
// Register global helpers
self.$RefreshHelpers$ = helpers_1.default;
// Register a helper for module execution interception
self.$RefreshInterceptModuleExecution$ = function (webpackModuleId) {
var prevRefreshReg = self.$RefreshReg$;
var prevRefreshSig = self.$RefreshSig$;
self.$RefreshReg$ = function (type, id) {
runtime_1.default.register(type, webpackModuleId + ' ' + id);
};
self.$RefreshSig$ = runtime_1.default.createSignatureFunctionForTransform;
// Modeled after `useEffect` cleanup pattern:
// https://react.dev/learn/synchronizing-with-effects#step-3-add-cleanup-if-needed
return function () {
self.$RefreshReg$ = prevRefreshReg;
self.$RefreshSig$ = prevRefreshSig;
};
};
//# sourceMappingURL=runtime.js.map