gatsby-plugin-image 2.1.0-next.2 → 2.1.3
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/dist/babel-helpers.js +66 -66
- package/dist/babel-plugin-parse-static-images.js +80 -80
- package/dist/components/gatsby-image.browser.js +247 -247
- package/dist/components/gatsby-image.server.js +112 -112
- package/dist/components/hooks.js +399 -399
- package/dist/components/intersection-observer.js +55 -55
- package/dist/components/layout-wrapper.js +94 -94
- package/dist/components/lazy-hydrate.js +75 -75
- package/dist/components/main-image.js +43 -43
- package/dist/components/picture.js +96 -96
- package/dist/components/placeholder.js +74 -74
- package/dist/components/static-image.server.js +111 -111
- package/dist/gatsby-node.js +54 -54
- package/dist/image-utils.js +449 -449
- package/dist/index.js +27 -27
- package/dist/node-apis/image-processing.js +278 -278
- package/dist/node-apis/node-utils.js +11 -11
- package/dist/node-apis/parser.js +98 -98
- package/dist/node-apis/preprocess-source.js +118 -118
- package/dist/node-apis/watcher.js +129 -129
- package/dist/resolver-utils.js +119 -119
- package/dist/src/babel-helpers.d.ts +6 -6
- package/dist/src/babel-plugin-parse-static-images.d.ts +10 -10
- package/dist/src/gatsby-node.d.ts +5 -5
- package/dist/src/node-apis/image-processing.d.ts +30 -30
- package/dist/src/node-apis/node-utils.d.ts +1 -1
- package/dist/src/node-apis/parser.d.ts +11 -11
- package/dist/src/node-apis/preprocess-source.d.ts +2 -2
- package/dist/src/node-apis/watcher.d.ts +12 -12
- package/dist/src/resolver-utils.d.ts +21 -21
- package/package.json +4 -4
package/dist/node-apis/parser.js
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
exports.__esModule = true;
|
|
17
|
-
exports.extractStaticImageProps = exports.babelParseToAst = exports.getBabelParserOptions = void 0;
|
|
18
|
-
var traverse_1 = __importDefault(require("@babel/traverse"));
|
|
19
|
-
var parser_1 = require("@babel/parser");
|
|
20
|
-
var babel_helpers_1 = require("../babel-helpers");
|
|
21
|
-
var PARSER_OPTIONS = {
|
|
22
|
-
allowImportExportEverywhere: true,
|
|
23
|
-
allowReturnOutsideFunction: true,
|
|
24
|
-
allowSuperOutsideMethod: true,
|
|
25
|
-
sourceType: "unambiguous",
|
|
26
|
-
plugins: [
|
|
27
|
-
"jsx",
|
|
28
|
-
"flow",
|
|
29
|
-
"doExpressions",
|
|
30
|
-
"objectRestSpread",
|
|
31
|
-
[
|
|
32
|
-
"decorators",
|
|
33
|
-
{
|
|
34
|
-
decoratorsBeforeExport: true
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
"classProperties",
|
|
38
|
-
"classPrivateProperties",
|
|
39
|
-
"classPrivateMethods",
|
|
40
|
-
"exportDefaultFrom",
|
|
41
|
-
"exportNamespaceFrom",
|
|
42
|
-
"asyncGenerators",
|
|
43
|
-
"functionBind",
|
|
44
|
-
"functionSent",
|
|
45
|
-
"dynamicImport",
|
|
46
|
-
"numericSeparator",
|
|
47
|
-
"optionalChaining",
|
|
48
|
-
"importMeta",
|
|
49
|
-
"bigInt",
|
|
50
|
-
"optionalCatchBinding",
|
|
51
|
-
"throwExpressions",
|
|
52
|
-
[
|
|
53
|
-
"pipelineOperator",
|
|
54
|
-
{
|
|
55
|
-
proposal: "minimal"
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
"nullishCoalescingOperator",
|
|
59
|
-
]
|
|
60
|
-
};
|
|
61
|
-
function getBabelParserOptions(filePath) {
|
|
62
|
-
// Flow and TypeScript plugins can't be enabled simultaneously
|
|
63
|
-
if (/\.tsx?/.test(filePath)) {
|
|
64
|
-
var plugins = PARSER_OPTIONS.plugins;
|
|
65
|
-
return __assign(__assign({}, PARSER_OPTIONS), { plugins: (plugins || []).map(function (plugin) {
|
|
66
|
-
return plugin === "flow" ? "typescript" : plugin;
|
|
67
|
-
}) });
|
|
68
|
-
}
|
|
69
|
-
return PARSER_OPTIONS;
|
|
70
|
-
}
|
|
71
|
-
exports.getBabelParserOptions = getBabelParserOptions;
|
|
72
|
-
function babelParseToAst(contents, filePath) {
|
|
73
|
-
return (0, parser_1.parse)(contents, getBabelParserOptions(filePath));
|
|
74
|
-
}
|
|
75
|
-
exports.babelParseToAst = babelParseToAst;
|
|
76
|
-
/**
|
|
77
|
-
* Traverses the parsed source, looking for StaticImage components.
|
|
78
|
-
* Extracts and returns the props from any that are found
|
|
79
|
-
*/
|
|
80
|
-
var extractStaticImageProps = function (ast, onError) {
|
|
81
|
-
var images = new Map();
|
|
82
|
-
(0, traverse_1["default"])(ast, {
|
|
83
|
-
JSXOpeningElement: function (nodePath) {
|
|
84
|
-
// Is this a StaticImage?
|
|
85
|
-
if (!nodePath
|
|
86
|
-
.get("name")
|
|
87
|
-
.referencesImport("gatsby-plugin-image", "StaticImage")) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
var image = (0, babel_helpers_1.evaluateImageAttributes)(
|
|
91
|
-
// There's a conflict between the definition of NodePath in @babel/core and @babel/traverse
|
|
92
|
-
nodePath, onError);
|
|
93
|
-
images.set((0, babel_helpers_1.hashOptions)(image), image);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
return images;
|
|
97
|
-
};
|
|
98
|
-
exports.extractStaticImageProps = extractStaticImageProps;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
exports.__esModule = true;
|
|
17
|
+
exports.extractStaticImageProps = exports.babelParseToAst = exports.getBabelParserOptions = void 0;
|
|
18
|
+
var traverse_1 = __importDefault(require("@babel/traverse"));
|
|
19
|
+
var parser_1 = require("@babel/parser");
|
|
20
|
+
var babel_helpers_1 = require("../babel-helpers");
|
|
21
|
+
var PARSER_OPTIONS = {
|
|
22
|
+
allowImportExportEverywhere: true,
|
|
23
|
+
allowReturnOutsideFunction: true,
|
|
24
|
+
allowSuperOutsideMethod: true,
|
|
25
|
+
sourceType: "unambiguous",
|
|
26
|
+
plugins: [
|
|
27
|
+
"jsx",
|
|
28
|
+
"flow",
|
|
29
|
+
"doExpressions",
|
|
30
|
+
"objectRestSpread",
|
|
31
|
+
[
|
|
32
|
+
"decorators",
|
|
33
|
+
{
|
|
34
|
+
decoratorsBeforeExport: true
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
"classProperties",
|
|
38
|
+
"classPrivateProperties",
|
|
39
|
+
"classPrivateMethods",
|
|
40
|
+
"exportDefaultFrom",
|
|
41
|
+
"exportNamespaceFrom",
|
|
42
|
+
"asyncGenerators",
|
|
43
|
+
"functionBind",
|
|
44
|
+
"functionSent",
|
|
45
|
+
"dynamicImport",
|
|
46
|
+
"numericSeparator",
|
|
47
|
+
"optionalChaining",
|
|
48
|
+
"importMeta",
|
|
49
|
+
"bigInt",
|
|
50
|
+
"optionalCatchBinding",
|
|
51
|
+
"throwExpressions",
|
|
52
|
+
[
|
|
53
|
+
"pipelineOperator",
|
|
54
|
+
{
|
|
55
|
+
proposal: "minimal"
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
"nullishCoalescingOperator",
|
|
59
|
+
]
|
|
60
|
+
};
|
|
61
|
+
function getBabelParserOptions(filePath) {
|
|
62
|
+
// Flow and TypeScript plugins can't be enabled simultaneously
|
|
63
|
+
if (/\.tsx?/.test(filePath)) {
|
|
64
|
+
var plugins = PARSER_OPTIONS.plugins;
|
|
65
|
+
return __assign(__assign({}, PARSER_OPTIONS), { plugins: (plugins || []).map(function (plugin) {
|
|
66
|
+
return plugin === "flow" ? "typescript" : plugin;
|
|
67
|
+
}) });
|
|
68
|
+
}
|
|
69
|
+
return PARSER_OPTIONS;
|
|
70
|
+
}
|
|
71
|
+
exports.getBabelParserOptions = getBabelParserOptions;
|
|
72
|
+
function babelParseToAst(contents, filePath) {
|
|
73
|
+
return (0, parser_1.parse)(contents, getBabelParserOptions(filePath));
|
|
74
|
+
}
|
|
75
|
+
exports.babelParseToAst = babelParseToAst;
|
|
76
|
+
/**
|
|
77
|
+
* Traverses the parsed source, looking for StaticImage components.
|
|
78
|
+
* Extracts and returns the props from any that are found
|
|
79
|
+
*/
|
|
80
|
+
var extractStaticImageProps = function (ast, onError) {
|
|
81
|
+
var images = new Map();
|
|
82
|
+
(0, traverse_1["default"])(ast, {
|
|
83
|
+
JSXOpeningElement: function (nodePath) {
|
|
84
|
+
// Is this a StaticImage?
|
|
85
|
+
if (!nodePath
|
|
86
|
+
.get("name")
|
|
87
|
+
.referencesImport("gatsby-plugin-image", "StaticImage")) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
var image = (0, babel_helpers_1.evaluateImageAttributes)(
|
|
91
|
+
// There's a conflict between the definition of NodePath in @babel/core and @babel/traverse
|
|
92
|
+
nodePath, onError);
|
|
93
|
+
images.set((0, babel_helpers_1.hashOptions)(image), image);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return images;
|
|
97
|
+
};
|
|
98
|
+
exports.extractStaticImageProps = extractStaticImageProps;
|
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
16
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
17
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
18
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
19
|
-
function step(op) {
|
|
20
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
21
|
-
while (_) try {
|
|
22
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
23
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
24
|
-
switch (op[0]) {
|
|
25
|
-
case 0: case 1: t = op; break;
|
|
26
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
27
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
28
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
29
|
-
default:
|
|
30
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
31
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
32
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
33
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
34
|
-
if (t[2]) _.ops.pop();
|
|
35
|
-
_.trys.pop(); continue;
|
|
36
|
-
}
|
|
37
|
-
op = body.call(thisArg, _);
|
|
38
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
39
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
-
};
|
|
45
|
-
exports.__esModule = true;
|
|
46
|
-
exports.preprocessSource = void 0;
|
|
47
|
-
var parser_1 = require("./parser");
|
|
48
|
-
var path_1 = __importDefault(require("path"));
|
|
49
|
-
var parser_2 = require("./parser");
|
|
50
|
-
var code_frame_1 = require("@babel/code-frame");
|
|
51
|
-
var image_processing_1 = require("./image-processing");
|
|
52
|
-
var node_utils_1 = require("./node-utils");
|
|
53
|
-
var common_tags_1 = require("common-tags");
|
|
54
|
-
var extensions = [".js", ".jsx", ".tsx"];
|
|
55
|
-
function preprocessSource(_a) {
|
|
56
|
-
var filename = _a.filename, contents = _a.contents, pathPrefix = _a.pathPrefix, cache = _a.cache, reporter = _a.reporter, store = _a.store, createNodeId = _a.createNodeId, createNode = _a.actions.createNode;
|
|
57
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
-
var root, cacheDir, ast, images, sourceDir;
|
|
59
|
-
return __generator(this, function (_b) {
|
|
60
|
-
switch (_b.label) {
|
|
61
|
-
case 0:
|
|
62
|
-
if (!contents.includes("StaticImage") ||
|
|
63
|
-
!contents.includes("gatsby-plugin-image") ||
|
|
64
|
-
!extensions.includes(path_1["default"].extname(filename))) {
|
|
65
|
-
return [2 /*return*/];
|
|
66
|
-
}
|
|
67
|
-
root = store.getState().program.directory;
|
|
68
|
-
cacheDir = (0, node_utils_1.getCacheDir)(root);
|
|
69
|
-
ast = (0, parser_1.babelParseToAst)(contents, filename);
|
|
70
|
-
reporter.setErrorMap({
|
|
71
|
-
"95314": {
|
|
72
|
-
text: function (context) {
|
|
73
|
-
return (0, common_tags_1.stripIndents)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n Error extracting property \"", "\" from StaticImage component.\n There are restrictions on how props can be passed to the StaticImage component. Learn more at https://gatsby.dev/static-image-props\n\n ", "\n "], ["\n Error extracting property \"", "\" from StaticImage component.\n There are restrictions on how props can be passed to the StaticImage component. Learn more at https://gatsby.dev/static-image-props\n\n ", "\n "])), context.prop, context.codeFrame);
|
|
74
|
-
},
|
|
75
|
-
docsUrl: "https://gatsby.dev/static-image-props",
|
|
76
|
-
level: "ERROR",
|
|
77
|
-
category: "USER"
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
images = (0, parser_2.extractStaticImageProps)(ast, function (prop, nodePath) {
|
|
81
|
-
var _a = nodePath.node.loc, start = _a.start, end = _a.end;
|
|
82
|
-
var location = { start: start, end: end };
|
|
83
|
-
reporter.error({
|
|
84
|
-
id: "95314",
|
|
85
|
-
filePath: filename,
|
|
86
|
-
location: location,
|
|
87
|
-
context: {
|
|
88
|
-
prop: prop,
|
|
89
|
-
codeFrame: (0, code_frame_1.codeFrameColumns)(contents, nodePath.node.loc, {
|
|
90
|
-
linesAbove: 6,
|
|
91
|
-
linesBelow: 6,
|
|
92
|
-
highlightCode: true
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
sourceDir = path_1["default"].dirname(filename);
|
|
98
|
-
return [4 /*yield*/, (0, image_processing_1.writeImages)({
|
|
99
|
-
images: images,
|
|
100
|
-
pathPrefix: pathPrefix,
|
|
101
|
-
cache: cache,
|
|
102
|
-
reporter: reporter,
|
|
103
|
-
cacheDir: cacheDir,
|
|
104
|
-
sourceDir: sourceDir,
|
|
105
|
-
createNodeId: createNodeId,
|
|
106
|
-
createNode: createNode,
|
|
107
|
-
store: store,
|
|
108
|
-
filename: filename
|
|
109
|
-
})];
|
|
110
|
-
case 1:
|
|
111
|
-
_b.sent();
|
|
112
|
-
return [2 /*return*/];
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
exports.preprocessSource = preprocessSource;
|
|
118
|
-
var templateObject_1;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
16
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
17
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
18
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
19
|
+
function step(op) {
|
|
20
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
21
|
+
while (_) try {
|
|
22
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
23
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
24
|
+
switch (op[0]) {
|
|
25
|
+
case 0: case 1: t = op; break;
|
|
26
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
27
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
28
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
29
|
+
default:
|
|
30
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
31
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
32
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
33
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
34
|
+
if (t[2]) _.ops.pop();
|
|
35
|
+
_.trys.pop(); continue;
|
|
36
|
+
}
|
|
37
|
+
op = body.call(thisArg, _);
|
|
38
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
39
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
+
};
|
|
45
|
+
exports.__esModule = true;
|
|
46
|
+
exports.preprocessSource = void 0;
|
|
47
|
+
var parser_1 = require("./parser");
|
|
48
|
+
var path_1 = __importDefault(require("path"));
|
|
49
|
+
var parser_2 = require("./parser");
|
|
50
|
+
var code_frame_1 = require("@babel/code-frame");
|
|
51
|
+
var image_processing_1 = require("./image-processing");
|
|
52
|
+
var node_utils_1 = require("./node-utils");
|
|
53
|
+
var common_tags_1 = require("common-tags");
|
|
54
|
+
var extensions = [".js", ".jsx", ".tsx"];
|
|
55
|
+
function preprocessSource(_a) {
|
|
56
|
+
var filename = _a.filename, contents = _a.contents, pathPrefix = _a.pathPrefix, cache = _a.cache, reporter = _a.reporter, store = _a.store, createNodeId = _a.createNodeId, createNode = _a.actions.createNode;
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var root, cacheDir, ast, images, sourceDir;
|
|
59
|
+
return __generator(this, function (_b) {
|
|
60
|
+
switch (_b.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
if (!contents.includes("StaticImage") ||
|
|
63
|
+
!contents.includes("gatsby-plugin-image") ||
|
|
64
|
+
!extensions.includes(path_1["default"].extname(filename))) {
|
|
65
|
+
return [2 /*return*/];
|
|
66
|
+
}
|
|
67
|
+
root = store.getState().program.directory;
|
|
68
|
+
cacheDir = (0, node_utils_1.getCacheDir)(root);
|
|
69
|
+
ast = (0, parser_1.babelParseToAst)(contents, filename);
|
|
70
|
+
reporter.setErrorMap({
|
|
71
|
+
"95314": {
|
|
72
|
+
text: function (context) {
|
|
73
|
+
return (0, common_tags_1.stripIndents)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n Error extracting property \"", "\" from StaticImage component.\n There are restrictions on how props can be passed to the StaticImage component. Learn more at https://gatsby.dev/static-image-props\n\n ", "\n "], ["\n Error extracting property \"", "\" from StaticImage component.\n There are restrictions on how props can be passed to the StaticImage component. Learn more at https://gatsby.dev/static-image-props\n\n ", "\n "])), context.prop, context.codeFrame);
|
|
74
|
+
},
|
|
75
|
+
docsUrl: "https://gatsby.dev/static-image-props",
|
|
76
|
+
level: "ERROR",
|
|
77
|
+
category: "USER"
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
images = (0, parser_2.extractStaticImageProps)(ast, function (prop, nodePath) {
|
|
81
|
+
var _a = nodePath.node.loc, start = _a.start, end = _a.end;
|
|
82
|
+
var location = { start: start, end: end };
|
|
83
|
+
reporter.error({
|
|
84
|
+
id: "95314",
|
|
85
|
+
filePath: filename,
|
|
86
|
+
location: location,
|
|
87
|
+
context: {
|
|
88
|
+
prop: prop,
|
|
89
|
+
codeFrame: (0, code_frame_1.codeFrameColumns)(contents, nodePath.node.loc, {
|
|
90
|
+
linesAbove: 6,
|
|
91
|
+
linesBelow: 6,
|
|
92
|
+
highlightCode: true
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
sourceDir = path_1["default"].dirname(filename);
|
|
98
|
+
return [4 /*yield*/, (0, image_processing_1.writeImages)({
|
|
99
|
+
images: images,
|
|
100
|
+
pathPrefix: pathPrefix,
|
|
101
|
+
cache: cache,
|
|
102
|
+
reporter: reporter,
|
|
103
|
+
cacheDir: cacheDir,
|
|
104
|
+
sourceDir: sourceDir,
|
|
105
|
+
createNodeId: createNodeId,
|
|
106
|
+
createNode: createNode,
|
|
107
|
+
store: store,
|
|
108
|
+
filename: filename
|
|
109
|
+
})];
|
|
110
|
+
case 1:
|
|
111
|
+
_b.sent();
|
|
112
|
+
return [2 /*return*/];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
exports.preprocessSource = preprocessSource;
|
|
118
|
+
var templateObject_1;
|