@posthog/nextjs-config
Version:
NextJS configuration helper for Posthog 🦔
94 lines (93 loc) • 3.63 kB
JavaScript
;
var __webpack_require__ = {};
(()=>{
__webpack_require__.n = (module)=>{
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
__webpack_require__.d(getter, {
a: getter
});
return getter;
};
})();
(()=>{
__webpack_require__.d = (exports1, definition)=>{
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
get: definition[key]
});
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
stripDanglingSourceMapComments: ()=>stripDanglingSourceMapComments
});
const promises_namespaceObject = require("fs/promises");
var promises_default = /*#__PURE__*/ __webpack_require__.n(promises_namespaceObject);
const external_path_namespaceObject = require("path");
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
const SOURCE_MAPPING_URL_COMMENT = /^[ \t]*\/\/# sourceMappingURL=([^\r\n]*)[ \t]*$/gm;
async function stripDanglingSourceMapComments(distDir) {
let jsFiles;
try {
jsFiles = await listJsFiles(external_path_default().join(distDir, 'static'));
} catch (e) {
return;
}
for (const file of jsFiles)try {
await stripDanglingComment(file);
} catch (e) {}
}
async function listJsFiles(dir) {
const files = [];
for (const entry of (await promises_default().readdir(dir, {
withFileTypes: true
}))){
const fullPath = external_path_default().join(dir, entry.name);
if (entry.isDirectory()) files.push(...await listJsFiles(fullPath));
else if (entry.isFile() && /\.[mc]?js$/.test(fullPath)) files.push(fullPath);
}
return files;
}
async function stripDanglingComment(file) {
const content = await promises_default().readFile(file, 'utf8');
const match = [
...content.matchAll(SOURCE_MAPPING_URL_COMMENT)
].pop();
if (!match) return;
var _match_;
const url = (null != (_match_ = match[1]) ? _match_ : '').trim();
if ('' === url || url.startsWith('data:') || url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//') || await exists(external_path_default().resolve(external_path_default().dirname(file), url))) return;
let lineEnd = match.index + match[0].length;
if ('\r' === content[lineEnd]) lineEnd += 1;
if ('\n' === content[lineEnd]) lineEnd += 1;
await promises_default().writeFile(file, content.slice(0, match.index) + content.slice(lineEnd), 'utf8');
}
async function exists(filePath) {
try {
await promises_default().access(filePath);
return true;
} catch (e) {
return false;
}
}
exports.stripDanglingSourceMapComments = __webpack_exports__.stripDanglingSourceMapComments;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
"stripDanglingSourceMapComments"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
value: true
});