UNPKG

6.77 kBSource Map (JSON)View Raw
1{"version":3,"file":"css-resource-plugin.js","sourceRoot":"","sources":["../../../src/lib/styles/css-resource-plugin.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAGH,+CAA4C;AAC5C,yCAAoD;AACpD,iEAAgD;AAEhD,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAEtD;;;GAGG;AACH,MAAM,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAElE;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CAAC,GAAW;IACjD,OAAO;QACL,IAAI,EAAE,sBAAsB;QAC5B,KAAK,CAAC,KAAkB;YACtB,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;;gBAC7C,kEAAkE;gBAClE,yEAAyE;gBACzE,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,KAAI,MAAA,IAAI,CAAC,UAAU,0CAAG,uBAAuB,CAAC,CAAA,EAAE,CAAC;oBAC5E,OAAO,IAAI,CAAC;gBACd,CAAC;gBAED,qFAAqF;gBACrF,qBAAqB;gBACrB,IAAI,GAAG,KAAK,6BAAM,CAAC,MAAM,IAAI,qCAAqC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;oBACnF,OAAO;wBACL,IAAI,EAAE,IAAI,CAAC,IAAI;wBACf,QAAQ,EAAE,IAAI;qBACf,CAAC;gBACJ,CAAC;gBAED,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC;gBACxE,UAAU,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC;gBAE3C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE;oBAC5C,QAAQ;oBACR,IAAI;oBACJ,SAAS;oBACT,UAAU;o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EAAE,GAAG,EAAE,SAAS,EAAE,sBAAsB,EAAE,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;;gBAC5E,MAAM,YAAY,GAAG,IAAA,gBAAI,EAAC,MAAA,KAAK,CAAC,cAAc,CAAC,aAAa,mCAAI,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAE/E,OAAO;oBACL,QAAQ,EAAE,MAAM,IAAA,mBAAQ,EAAC,YAAY,CAAC;oBACtC,MAAM,EAAE,SAAS;oBACjB,UAAU,EAAE,CAAC,YAAY,CAAC;iBAC3B,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC;AArFD,0DAqFC","sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport type { Plugin, PluginBuild } from 'esbuild';\nimport { readFile } from 'node:fs/promises';\nimport { extname, join, relative } from 'node:path';\nimport { CssUrl } from './stylesheet-processor';\n\nconst CSS_RESOURCE_NAMESPACE = 'angular:css-resource';\n\n/**\n * Symbol marker used to indicate CSS resource resolution is being attempted.\n * This is used to prevent an infinite loop within the plugin's resolve hook.\n */\nconst CSS_RESOURCE_RESOLUTION = Symbol('CSS_RESOURCE_RESOLUTION');\n\n/**\n * Creates an esbuild {@link Plugin} that loads all CSS url token references using the\n * built-in esbuild `file` loader. A plugin is used to allow for all file extensions\n * and types to be supported without needing to manually specify all extensions\n * within the build configuration.\n *\n * @returns An esbuild {@link Plugin} instance.\n */\nexport function createCssResourcePlugin(url: CssUrl): Plugin {\n return {\n name: 'angular-css-resource',\n setup(build: PluginBuild): void {\n build.onResolve({ filter: /.*/ }, async args => {\n // Only attempt to resolve url tokens which only exist inside CSS.\n // Also, skip this plugin if already attempting to resolve the url-token.\n if (args.kind !== 'url-token' || args.pluginData?.[CSS_RESOURCE_RESOLUTION]) {\n return null;\n }\n\n // If root-relative, absolute or protocol relative url, mark as external to leave the\n // path/URL in place.\n if (url !== CssUrl.inline || /^((?:\\w+:)?\\/\\/|data:|chrome:|#|\\/)/.test(args.path)) {\n return {\n path: args.path,\n external: true,\n };\n }\n\n const { importer, kind, resolveDir, namespace, pluginData = {} } = args;\n pluginData[CSS_RESOURCE_RESOLUTION] = true;\n\n const result = await build.resolve(args.path, {\n importer,\n kind,\n namespace,\n pluginData,\n resolveDir,\n });\n\n if (result.errors.length) {\n const error = result.errors[0];\n if (args.path[0] === '~') {\n error.notes = [\n {\n location: null,\n text: 'You can remove the tilde and use a relative path to reference it, which should remove this error.',\n },\n ];\n } else if (args.path[0] === '^') {\n error.notes = [\n {\n location: null,\n text: 'You can remove the caret and use a relative path to reference it, which should remove this error.',\n },\n ];\n }\n\n const extension = importer && extname(importer);\n if (extension !== '.css') {\n error.notes.push({\n location: null,\n text: 'Preprocessor stylesheets may not show the exact file location of the error.',\n });\n }\n }\n\n // Return results that are not files since these are most likely specific to another plugin\n // and cannot be loaded by this plugin.\n if (result.namespace !== 'file') {\n return result;\n }\n\n // All file results are considered CSS resources and will be loaded via the file loader\n return {\n ...result,\n // Use a relative path to prevent fully resolved paths in the metafile (JSON stats file).\n // This is only necessary for custom namespaces. esbuild will handle the file namespace.\n path: relative(build.initialOptions.absWorkingDir ?? '', result.path),\n namespace: CSS_RESOURCE_NAMESPACE,\n };\n });\n\n build.onLoad({ filter: /./, namespace: CSS_RESOURCE_NAMESPACE }, async args => {\n const resourcePath = join(build.initialOptions.absWorkingDir ?? '', args.path);\n\n return {\n contents: await readFile(resourcePath),\n loader: 'dataurl',\n watchFiles: [resourcePath],\n };\n });\n },\n };\n}\n"]}
\No newline at end of file