reactivated 0.28.2 → 0.29.0-a1475

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.
@@ -23,11 +23,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  __setModuleDefault(result, mod);
24
24
  return result;
25
25
  };
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
26
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
27
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
37
  };
29
38
  Object.defineProperty(exports, "__esModule", { value: true });
30
- const esbuild_1 = __importDefault(require("@linaria/esbuild"));
39
+ const linaria_1 = __importDefault(require("./linaria"));
31
40
  const esbuild_plugin_1 = require("@vanilla-extract/esbuild-plugin");
32
41
  const esbuild = __importStar(require("esbuild"));
33
42
  const esbuild_plugin_import_glob_1 = __importDefault(require("esbuild-plugin-import-glob"));
@@ -41,7 +50,7 @@ const env = {
41
50
  TAG_VERSION: process.env.TAG_VERSION,
42
51
  };
43
52
  esbuild
44
- .build({
53
+ .context({
45
54
  entryPoints,
46
55
  bundle: true,
47
56
  // We use terser to minify because esbuild breaks safari sourcemaps.
@@ -54,7 +63,6 @@ esbuild
54
63
  sourcemap: true,
55
64
  target: "es2018",
56
65
  preserveSymlinks: true,
57
- watch: production === false,
58
66
  external: ["moment", "@client/generated/images"],
59
67
  define: {
60
68
  // You need both. The one from the stringified JSON is not picked
@@ -82,8 +90,16 @@ esbuild
82
90
  // Instead of set it manually instead of relying on minification
83
91
  // settings.
84
92
  (0, esbuild_plugin_1.vanillaExtractPlugin)({ identifiers }),
85
- (0, esbuild_1.default)({ sourceMap: true, esbuildOptions: { sourcemap: "inline" } }),
93
+ (0, linaria_1.default)({ sourceMap: true, esbuildOptions: { sourcemap: "inline" } }),
86
94
  ],
87
95
  })
88
- .catch(() => process.exit(1));
96
+ .then((context) => __awaiter(void 0, void 0, void 0, function* () {
97
+ if (production === false) {
98
+ context.watch();
99
+ }
100
+ else {
101
+ yield context.rebuild();
102
+ process.exit();
103
+ }
104
+ }));
89
105
  //# sourceMappingURL=build.client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.client.js","sourceRoot":"","sources":["../src/build.client.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,+DAAuC;AACvC,oEAAqE;AACrE,iDAAmC;AACnC,4FAA0D;AAE1D,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEzC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAClC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,MAAM,CAAC,CAAC,CAC9D,CAAC;AAEF,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AACzD,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AAEnD,MAAM,GAAG,GAAG;IACR,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa;IACnD,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;IACxC,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;CACvC,CAAC;AAEF,OAAO;KACF,KAAK,CAAC;IACH,WAAW;IACX,MAAM,EAAE,IAAI;IACZ,oEA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M,EAAE;QACJ,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,MAAM;KACnB;IACD,OAAO,EAAE;QACL,IAAA,oCAAgB,GAAE;QAClB,4DAA4D;QAC5D,gEAAgE;QAChE,UAAU;QACV,gEAAgE;QAChE,YAAY;QACZ,IAAA,qCAAoB,EAAC,EAAC,WAAW,EAAC,CAAC;QACnC,IAAA,iBAAO,EAAC,EAAC,SAAS,EAAE,IAAI,EAAE,cAAc,EAAE,EAAC,SAAS,EAAE,QAAQ,EAAC,EAAC,CAAC;KACpE;CACJ,CAAC;KACD,IAAI,CAAC,CAAO,OAAO,EAAE,EAAE;IACpB,IAAI,UAAU,KAAK,KAAK,EAAE;QACtB,OAAO,CAAC,KAAK,EAAE,CAAC;KACnB;SAAM;QACH,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,EAAE,CAAC;KAClB;AACL,CAAC,CAAA,CAAC,CAAC"}
@@ -23,11 +23,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  __setModuleDefault(result, mod);
24
24
  return result;
25
25
  };
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
26
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
27
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
37
  };
29
38
  Object.defineProperty(exports, "__esModule", { value: true });
30
- const esbuild_1 = __importDefault(require("@linaria/esbuild"));
39
+ const linaria_1 = __importDefault(require("./linaria"));
31
40
  const esbuild_plugin_1 = require("@vanilla-extract/esbuild-plugin");
32
41
  const esbuild = __importStar(require("esbuild"));
33
42
  const esbuild_plugin_import_glob_1 = __importDefault(require("esbuild-plugin-import-glob"));
@@ -35,8 +44,15 @@ let server = null;
35
44
  const CACHE_KEY = `${process.cwd()}/node_modules/_reactivated/renderer.js`;
36
45
  const production = process.env.NODE_ENV === "production";
37
46
  const identifiers = production ? "short" : "debug";
47
+ const restartServer = () => {
48
+ if (server != null) {
49
+ server.close();
50
+ }
51
+ delete require.cache[CACHE_KEY];
52
+ server = require(CACHE_KEY).server;
53
+ };
38
54
  esbuild
39
- .build({
55
+ .context({
40
56
  stdin: {
41
57
  contents: `
42
58
  export {server} from "reactivated/dist/renderer";
@@ -55,13 +71,6 @@ esbuild
55
71
  // of the location of reactivated being in the cwd node_modules or
56
72
  // above as in monorepos.
57
73
  nodePaths: [`${process.cwd()}/node_modules`],
58
- watch: production === true
59
- ? false
60
- : {
61
- onRebuild: () => {
62
- restartServer();
63
- },
64
- },
65
74
  plugins: [
66
75
  (0, esbuild_plugin_import_glob_1.default)(),
67
76
  // We manually pass in identifiers because the client is not
@@ -70,20 +79,26 @@ esbuild
70
79
  // Instead of set it manually instead of relying on minification
71
80
  // settings.
72
81
  (0, esbuild_plugin_1.vanillaExtractPlugin)({ identifiers }),
73
- (0, esbuild_1.default)({ sourceMap: true }),
82
+ (0, linaria_1.default)({ sourceMap: true }),
83
+ {
84
+ name: "restartServer",
85
+ setup: (build) => {
86
+ if (production === false) {
87
+ build.onEnd((result) => {
88
+ restartServer();
89
+ });
90
+ }
91
+ },
92
+ },
74
93
  ],
75
94
  })
76
- .then(() => {
95
+ .then((context) => __awaiter(void 0, void 0, void 0, function* () {
77
96
  if (production === false) {
78
- restartServer();
97
+ context.watch();
79
98
  }
80
- })
81
- .catch(() => process.exit(1));
82
- const restartServer = () => {
83
- if (server != null) {
84
- server.close();
99
+ else {
100
+ yield context.rebuild();
101
+ process.exit();
85
102
  }
86
- delete require.cache[CACHE_KEY];
87
- server = require(CACHE_KEY).server;
88
- };
103
+ }));
89
104
  //# sourceMappingURL=build.renderer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.renderer.js","sourceRoot":"","sources":["../src/build.renderer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,+DAAuC;AACvC,oEAAqE;AACrE,iDAAmC;AACnC,4FAA0D;AAI1D,IAAI,MAAM,GAAuB,IAAI,CAAC;AAEtC,MAAM,SAAS,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,wCAAwC,CAAC;AAC3E,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AACzD,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AAEnD,OAAO;KACF,KAAK,CAAC;IACH,KAAK,EAAE;QACH,QAAQ,EAAE;;aAET;QACD,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,EAAE,IAAI;KACf;IACD,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE,yCAAyC;IAClD,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,QAAQ;IAChB,gBAAgB,EAAE,IAAI;IACtB,gEAAgE;IAChE,kEAAkE;IAClE,yBAAyB;IACzB,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC;IAC5C,KAAK,EACD,UAAU,KAAK,IAAI;QACf,CAAC,CAAC,KAAK;QACP,CAAC,CAAC;YACI,SAAS,EAAE,GAAG,EAAE;gBACZ,aAAa,EAAE,CAAC;YACpB,CAAC;SACJ;IACX,OAAO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KAClB;AACL,CAAC,CAAA,CAAC,CAAC"}
@@ -80,7 +80,7 @@ export interface ClearableFileInput extends BaseWidget {
80
80
  initial_text: string;
81
81
  clear_checkbox_label: string;
82
82
  }
83
- declare type Optgroup = [
83
+ type Optgroup = [
84
84
  null,
85
85
  [
86
86
  {
@@ -119,7 +119,7 @@ export interface SelectDateWidget extends BaseWidget {
119
119
  subwidgets: [Select, Select, Select];
120
120
  template_name: "django/forms/widgets/select_date.html";
121
121
  }
122
- export declare type WidgetType = TextInput | URLInput | NumberInput | CheckboxInput | PasswordInput | EmailInput | HiddenInput | Textarea | Select | Autocomplete | SelectMultiple | DateInput | SelectDateWidget | ClearableFileInput;
122
+ export type WidgetType = TextInput | URLInput | NumberInput | CheckboxInput | PasswordInput | EmailInput | HiddenInput | Textarea | Select | Autocomplete | SelectMultiple | DateInput | SelectDateWidget | ClearableFileInput;
123
123
  export declare const getValue: (optgroup: Optgroup) => string | number;
124
124
  export declare const getValueForSelect: (widget: Select | Autocomplete | SelectMultiple) => string | string[];
125
125
  export declare const isHidden: (widget: WidgetType) => boolean;
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import { DjangoFormsWidgetsHiddenInput, Types } from "../generated";
3
3
  import { DiscriminateUnion } from "../types";
4
4
  import * as widgets from "./widgets";
5
- export declare type Optgroup = Types["Optgroup"];
5
+ export type Optgroup = Types["Optgroup"];
6
6
  export interface WidgetLike {
7
7
  name: string;
8
8
  tag: string;
@@ -45,10 +45,10 @@ export interface FormSetLike<T extends FieldMap<W>, W = WidgetLike> {
45
45
  forms: Array<FormLike<T, W>>;
46
46
  empty_form: FormLike<T, W>;
47
47
  }
48
- export declare type FormErrors<T extends FieldMap> = {
48
+ export type FormErrors<T extends FieldMap> = {
49
49
  [P in keyof T]?: string[];
50
50
  } | null;
51
- export declare type FormValues<T extends FieldMap> = {
51
+ export type FormValues<T extends FieldMap> = {
52
52
  [K in keyof T]: T[K] extends {
53
53
  enum: unknown;
54
54
  } ? T[K]["enum"] | null : T[K]["widget"] extends {
@@ -93,7 +93,7 @@ export declare const useForm: <T extends FieldMap<WidgetLike>>({ form, ...option
93
93
  fieldInterceptor?: ((fieldName: keyof T, field: FieldHandler<T[keyof T]["widget"]>, values: FormValues<T>) => FieldHandler<T[keyof T]["widget"]>) | undefined;
94
94
  changeInterceptor?: ((name: keyof T, prevValues: FormValues<T>, nextValues: FormValues<T>) => FormValues<T>) | undefined;
95
95
  }) => FormHandler<T>;
96
- export declare type CreateFieldHandler<T> = T extends {
96
+ export type CreateFieldHandler<T> = T extends {
97
97
  tag: string;
98
98
  name: string;
99
99
  subwidgets: infer U;
@@ -123,7 +123,7 @@ export interface WidgetHandler<T extends WidgetLike> {
123
123
  widget: T;
124
124
  handler: (value: T["value"]) => void;
125
125
  }
126
- export declare type FieldHandler<TWidget extends WidgetLike> = {
126
+ export type FieldHandler<TWidget extends WidgetLike> = {
127
127
  [K in TWidget["tag"]]: CreateFieldHandler<DiscriminateUnion<TWidget, "tag", K>>;
128
128
  }[TWidget["tag"]];
129
129
  interface BaseRendererProps<T extends FieldMap, F extends WidgetLike> {
@@ -140,7 +140,7 @@ interface ExcludeRendererProps<T extends FieldMap, F extends WidgetLike> extends
140
140
  fields?: never;
141
141
  exclude: Array<Extract<keyof T, string>>;
142
142
  }
143
- export declare type RendererProps<T extends FieldMap, F extends WidgetLike> = IncludeRendererProps<T, F> | ExcludeRendererProps<T, F>;
143
+ export type RendererProps<T extends FieldMap, F extends WidgetLike> = IncludeRendererProps<T, F> | ExcludeRendererProps<T, F>;
144
144
  export declare const createIterator: <F extends WidgetLike>() => <U extends FieldMap<WidgetLike>>(props: RendererProps<U, F>) => JSX.Element;
145
145
  export declare const Widget: (props: {
146
146
  field: FieldHandler<widgets.CoreWidget>;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { Types } from "../generated";
3
- export declare type CoreWidget = Types["Widget"];
4
- declare type Optgroup = Types["Optgroup"];
3
+ export type CoreWidget = Types["Widget"];
4
+ type Optgroup = Types["Optgroup"];
5
5
  export declare const CheckboxInput: (props: {
6
6
  name: string;
7
7
  className?: string | undefined;
@@ -5,6 +5,10 @@
5
5
  */
6
6
  export interface Types {
7
7
  Widget: DjangoFormsWidgetsHiddenInput | DjangoFormsWidgetsTextInput | DjangoFormsWidgetsNumberInput | DjangoFormsWidgetsURLInput | DjangoFormsWidgetsTimeInput | DjangoFormsWidgetsDateInput | DjangoFormsWidgetsCheckboxInput | DjangoFormsWidgetsPasswordInput | DjangoFormsWidgetsEmailInput | DjangoFormsWidgetsTextarea | DjangoFormsWidgetsSelect | DjangoFormsWidgetsSelectMultiple | DjangoFormsWidgetsClearableFileInput | DjangoFormsWidgetsSelectDateWidget | DjangoFormsWidgetsSplitDateTimeWidget;
8
+ /**
9
+ * @minItems 3
10
+ * @maxItems 3
11
+ */
8
12
  Optgroup: [null, [ReactivatedTypesOptgroupMember], number];
9
13
  URLSchema: {
10
14
  [k: string]: ReactivatedTypesURL;
@@ -219,6 +223,10 @@ export interface DjangoFormsWidgetsSelectDateWidget {
219
223
  month: string | null;
220
224
  day: string | null;
221
225
  };
226
+ /**
227
+ * @minItems 3
228
+ * @maxItems 3
229
+ */
222
230
  subwidgets: [DjangoFormsWidgetsSelect, DjangoFormsWidgetsSelect, DjangoFormsWidgetsSelect];
223
231
  tag: "django.forms.widgets.SelectDateWidget";
224
232
  }
@@ -233,6 +241,10 @@ export interface DjangoFormsWidgetsSplitDateTimeWidget {
233
241
  "0": string | null;
234
242
  "1": string | null;
235
243
  };
244
+ /**
245
+ * @minItems 2
246
+ * @maxItems 2
247
+ */
236
248
  subwidgets: [DjangoFormsWidgetsDateInput, DjangoFormsWidgetsTimeInput];
237
249
  tag: "django.forms.widgets.SplitDateTimeWidget";
238
250
  }
package/dist/generated.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- /* tslint:disable */
2
+ /* eslint-disable */
3
3
  /**
4
4
  * This file was automatically generated by json-schema-to-typescript.
5
5
  * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
package/dist/generator.js CHANGED
@@ -123,7 +123,7 @@ export type models = _Types["globals"]["models"];
123
123
  export const {Form, FormSet, Widget, useForm, useFormSet, ManagementForm} = forms;
124
124
  `);
125
125
  // tslint:disable-next-line
126
- (0, json_schema_to_typescript_1.compile)(types, "_Types").then((ts) => {
126
+ (0, json_schema_to_typescript_1.compile)(types, "this is unused").then((ts) => {
127
127
  process.stdout.write("/* eslint-disable */\n");
128
128
  process.stdout.write(ts);
129
129
  for (const name of Object.keys(templates)) {
@@ -1 +1 @@
1
- {"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.tsx"],"names":[],"mappings":";;;;;;AAEA,4CAAoB;AAGpB,wDAAwD;AACxD,qEAAqE;AACrE,MAAM,WAAW,GAAG,YAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEvC,yEAAkD;AAClD,uCAQkB;AAElB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACxD,MAAM,EAAC,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAC,GAAG,MAAM,CAAC;AAE/E,MAAM,IAAI,mCACH,iBAAiB,KACpB,wBAAwB,EAAE;QACtB,KAAK,EAAE,0BAA0B;QACjC,IAAI,EAAE,EAAE;KACX,EACD,6BAA6B,EAAE;QAC3B,KAAK,EAAE,+BAA+B;QACtC,IAAI,EAAE;YACF,CAAC,EAAE,QAAQ;SACd;KACJ,GACJ,CAAC;AAEF,MAAM,OAAO,GAAG,IAAI,kBAAO,EAAE,CAAC;AAE9B,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAEhD,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;IAChC,UAAU,CAAC,oBAAoB,CAAC;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AAS,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QACnC,UAAU,CAAC,aAAa,CAAC;;;kBAGf,IAAI,cAAc,SAAS;;;;SAIpC,CAAC,CAAC;KACN;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * This file contains an esbuild loader for Linaria.
3
+ * It uses the transform.ts function to generate class names from source code,
4
+ * returns transformed code without template literals and attaches generated source maps
5
+ */
6
+ import type { Plugin, TransformOptions } from "esbuild";
7
+ import type { PluginOptions, Preprocessor } from "@linaria/babel-preset";
8
+ type EsbuildPluginOptions = {
9
+ sourceMap?: boolean;
10
+ preprocessor?: Preprocessor;
11
+ esbuildOptions?: TransformOptions;
12
+ } & Partial<PluginOptions>;
13
+ export default function linaria({ sourceMap, preprocessor, esbuildOptions, ...rest }?: EsbuildPluginOptions): Plugin;
14
+ export {};
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ /**
3
+ * This file contains an esbuild loader for Linaria.
4
+ * It uses the transform.ts function to generate class names from source code,
5
+ * returns transformed code without template literals and attaches generated source maps
6
+ */
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ var __rest = (this && this.__rest) || function (s, e) {
17
+ var t = {};
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
19
+ t[p] = s[p];
20
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
21
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
22
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
23
+ t[p[i]] = s[p[i]];
24
+ }
25
+ return t;
26
+ };
27
+ var __importDefault = (this && this.__importDefault) || function (mod) {
28
+ return (mod && mod.__esModule) ? mod : { "default": mod };
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ const fs_1 = __importDefault(require("fs"));
32
+ const path_1 = __importDefault(require("path"));
33
+ const esbuild_1 = require("esbuild");
34
+ const babel_preset_1 = require("@linaria/babel-preset");
35
+ const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
36
+ function linaria(_a = {}) {
37
+ var { sourceMap, preprocessor, esbuildOptions } = _a, rest = __rest(_a, ["sourceMap", "preprocessor", "esbuildOptions"]);
38
+ let options = esbuildOptions;
39
+ return {
40
+ name: "linaria",
41
+ setup(build) {
42
+ const cssLookup = new Map();
43
+ const asyncResolve = (token, importer) => __awaiter(this, void 0, void 0, function* () {
44
+ const context = path_1.default.isAbsolute(importer)
45
+ ? path_1.default.dirname(importer)
46
+ : path_1.default.join(process.cwd(), path_1.default.dirname(importer));
47
+ const result = yield build.resolve(token, {
48
+ kind: "entry-point",
49
+ resolveDir: context,
50
+ });
51
+ if (result.errors.length > 0) {
52
+ throw new Error(`Cannot resolve ${token}`);
53
+ }
54
+ return result.path;
55
+ });
56
+ build.onResolve({ filter: /\.linaria\.css$/ }, (args) => {
57
+ return {
58
+ namespace: "linaria",
59
+ path: args.path,
60
+ };
61
+ });
62
+ build.onLoad({ filter: /.*/, namespace: "linaria" }, (args) => {
63
+ return {
64
+ contents: cssLookup.get(args.path),
65
+ loader: "css",
66
+ resolveDir: path_1.default.basename(args.path),
67
+ };
68
+ });
69
+ build.onLoad({ filter: /\.(js|jsx|ts|tsx)$/ }, (args) => __awaiter(this, void 0, void 0, function* () {
70
+ const rawCode = fs_1.default.readFileSync(args.path, "utf8");
71
+ const { ext, name: filename } = path_1.default.parse(args.path);
72
+ const loader = ext.replace(/^\./, "");
73
+ if (nodeModulesRegex.test(args.path)) {
74
+ return {
75
+ loader,
76
+ contents: rawCode,
77
+ };
78
+ }
79
+ if (!options) {
80
+ options = {};
81
+ if ("jsxFactory" in build.initialOptions) {
82
+ options.jsxFactory = build.initialOptions.jsxFactory;
83
+ }
84
+ if ("jsxFragment" in build.initialOptions) {
85
+ options.jsxFragment = build.initialOptions.jsxFragment;
86
+ }
87
+ }
88
+ const transformed = (0, esbuild_1.transformSync)(rawCode, Object.assign(Object.assign({}, options), { sourcefile: args.path, sourcemap: sourceMap, loader }));
89
+ let { code } = transformed;
90
+ if (sourceMap) {
91
+ const esbuildMap = Buffer.from(transformed.map).toString("base64");
92
+ code += `/*# sourceMappingURL=data:application/json;base64,${esbuildMap}*/`;
93
+ }
94
+ const result = yield (0, babel_preset_1.transform)(code, {
95
+ filename: args.path,
96
+ preprocessor,
97
+ pluginOptions: rest,
98
+ }, asyncResolve);
99
+ if (!result.cssText) {
100
+ return {
101
+ contents: code,
102
+ loader,
103
+ resolveDir: path_1.default.dirname(args.path),
104
+ };
105
+ }
106
+ let { cssText } = result;
107
+ const slug = (0, babel_preset_1.slugify)(cssText);
108
+ const cssFilename = `${filename}_${slug}.linaria.css`;
109
+ let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;
110
+ if (sourceMap && result.cssSourceMapText) {
111
+ const map = Buffer.from(result.cssSourceMapText).toString("base64");
112
+ cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
113
+ const linariaMap = Buffer.from(JSON.stringify(result.sourceMap)).toString("base64");
114
+ contents += `/*# sourceMappingURL=data:application/json;base64,${linariaMap}*/`;
115
+ }
116
+ cssLookup.set(cssFilename, cssText);
117
+ return {
118
+ contents,
119
+ loader,
120
+ resolveDir: path_1.default.dirname(args.path),
121
+ };
122
+ }));
123
+ },
124
+ };
125
+ }
126
+ exports.default = linaria;
127
+ //# sourceMappingURL=linaria.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linaria.js","sourceRoot":"","sources":["../src/linaria.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAAoB;AACpB,gDAAwB;AAGxB,qCAAsC;AAGtC,wDAAyD;AAQzD,MAAM,gBAAgB,GAAG,wCAAwC,CAAC;AAElE,SAAwB,OAAO,CAAC,KAKN,EAAE;QALI,EAC5B,SAAS,EACT,YAAY,EACZ,cAAc,OAEU,EADrB,IAAI,cAJqB,+CAK/B,CADU;IAEP,IAAI,OAAO,GAAG,cAAc,CAAC;IAC7B,OAAO;QACH,IAAI,EAAE,SAAS;QACf,KAAK,CAAC,KAAK;YACP,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;YAE5C,MAAM,YAAY,GAAG,CACjB,KAAa,EACb,QAAgB,EACD,EAAE;gBACjB,MAAM,OAAO,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;oBACrC,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;oBACxB,CAAC,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAEvD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE;oBACtC,IAAI,EAAE,aAAa;oBACnB,UAAU,EAAE,OAAO;iBACtB,CAAC,CAAC;gBAEH,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;oBAC1B,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,EAAE,CAAC,CAAC;iBAC9C;gBAED,OAAO,MAAM,CAAC,IAAI,CAAC;YACvB,CAAC,CAAA,CAAC;YAEF,KAAK,CAAC,SAAS,CAAC,EAAC,MAAM,EAAE,iBAAiB,E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QAAQ,CAAC,CAAC;oBACpE,OAAO,IAAI,qDAAqD,GAAG,IAAI,CAAC;oBACxE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAC1B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CACnC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;oBACrB,QAAQ,IAAI,qDAAqD,UAAU,IAAI,CAAC;iBACnF;gBAED,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;gBAEpC,OAAO;oBACH,QAAQ;oBACR,MAAM;oBACN,UAAU,EAAE,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;iBACtC,CAAC;YACN,CAAC,CAAA,CAAC,CAAC;QACP,CAAC;KACJ,CAAC;AACN,CAAC;AA9HD,0BA8HC"}
@@ -9,7 +9,7 @@ export declare const renderPage: ({ html, helmet, context, props, }: {
9
9
  context: any;
10
10
  props: any;
11
11
  }) => string;
12
- declare type Result = {
12
+ type Result = {
13
13
  status: "success";
14
14
  rendered: string;
15
15
  } | {
@@ -23,5 +23,5 @@ export declare const render: ({ context, props }: {
23
23
  export declare const simpleRender: () => void;
24
24
  export declare const serverRender: (body: Buffer) => Result;
25
25
  export declare const SOCKET_PATH: string;
26
- export declare const server: http.Server;
26
+ export declare const server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
27
27
  export {};
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- export declare type DiscriminateUnion<T, K extends keyof T, V extends T[K]> = T extends Record<K, V> ? T : never;
1
+ export type DiscriminateUnion<T, K extends keyof T, V extends T[K]> = T extends Record<K, V> ? T : never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactivated",
3
- "version": "0.28.2",
3
+ "version": "0.29.0-a1475",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -17,38 +17,43 @@
17
17
  "build.renderer.js": "./dist/build.renderer.js"
18
18
  },
19
19
  "license": "ISC",
20
- "dependencies": {},
21
20
  "peerDependencies": {
22
- "@babel/core": "^7.16.7",
23
- "@babel/preset-react": "^7.17.12",
24
- "@babel/preset-typescript": "^7.16.7",
25
- "@linaria/babel-preset": "3.0.0-beta.21",
26
- "@linaria/core": "3.0.0-beta.21",
27
- "@linaria/esbuild": "3.0.0-beta.21",
28
- "@linaria/react": "3.0.0-beta.21",
29
- "@linaria/shaker": "3.0.0-beta.21",
21
+ "@babel/core": "^7.21.8",
22
+ "@babel/preset-react": "^7.18.6",
23
+ "@babel/preset-typescript": "^7.21.5",
24
+ "@linaria/babel-preset": "^4.4.5",
25
+ "@linaria/core": "^4.2.10",
26
+ "@linaria/esbuild": "^4.2.11",
27
+ "@linaria/react": "^4.3.8",
28
+ "@linaria/shaker": "^4.2.11",
30
29
  "@types/react": "^18.0.12",
31
30
  "@types/react-dom": "^18.0.5",
32
- "@typescript-eslint/eslint-plugin": "^5.30.6",
33
- "@typescript-eslint/parser": "^5.30.6",
34
- "@vanilla-extract/css": "^1.6.8",
35
- "@vanilla-extract/esbuild-plugin": "^2.0.2",
36
- "babel-plugin-module-resolver": "^4.1.0",
31
+ "@typescript-eslint/eslint-plugin": "^5.59.6",
32
+ "@typescript-eslint/parser": "^5.59.6",
33
+ "@vanilla-extract/css": "^1.11.0",
34
+ "@vanilla-extract/css-utils": "^0.1.3",
35
+ "@vanilla-extract/dynamic": "^2.0.3",
36
+ "@vanilla-extract/esbuild-plugin": "^2.2.2",
37
+ "@vanilla-extract/recipes": "^0.4.0",
38
+ "@vanilla-extract/sprinkles": "^1.6.0",
39
+ "babel-plugin-module-resolver": "^5.0.0",
40
+ "esbuild": "^0.17.19",
37
41
  "esbuild-plugin-import-glob": "^0.1.1",
38
- "eslint": "^8.19.0",
39
- "eslint-config-prettier": "^8.5.0",
40
- "eslint-import-resolver-typescript": "^3.2.5",
41
- "eslint-plugin-import": "^2.26.0",
42
- "eslint-plugin-react": "^7.30.1",
42
+ "eslint": "^8.40.0",
43
+ "eslint-config-prettier": "^8.8.0",
44
+ "eslint-import-resolver-typescript": "^3.5.5",
45
+ "eslint-plugin-import": "^2.27.5",
46
+ "eslint-plugin-react": "^7.32.2",
43
47
  "eslint-plugin-react-hooks": "^4.6.0",
44
48
  "eslint-plugin-unused-imports": "^2.0.0",
45
49
  "immer": "^9.0.7",
46
- "json-schema-to-typescript": "^10.1.5",
50
+ "json-schema-to-typescript": "^13.0.1",
51
+ "prettier": "^2.8.8",
47
52
  "react": "^18.1.0",
48
53
  "react-dom": "^18.1.0",
49
54
  "react-helmet-async": "^1.3.0",
50
55
  "terser": "^5.10.0",
51
- "ts-morph": "^13.0.2",
52
- "typescript": "^4.7.4"
56
+ "ts-morph": "^18.0.0",
57
+ "typescript": "^5.0.4"
53
58
  }
54
59
  }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import linaria from "@linaria/esbuild";
3
+ import linaria from "./linaria";
4
4
  import {vanillaExtractPlugin} from "@vanilla-extract/esbuild-plugin";
5
5
  import * as esbuild from "esbuild";
6
6
  import ImportGlobPlugin from "esbuild-plugin-import-glob";
@@ -21,7 +21,7 @@ const env = {
21
21
  };
22
22
 
23
23
  esbuild
24
- .build({
24
+ .context({
25
25
  entryPoints,
26
26
  bundle: true,
27
27
  // We use terser to minify because esbuild breaks safari sourcemaps.
@@ -34,7 +34,6 @@ esbuild
34
34
  sourcemap: true,
35
35
  target: "es2018",
36
36
  preserveSymlinks: true,
37
- watch: production === false,
38
37
  external: ["moment", "@client/generated/images"],
39
38
  define: {
40
39
  // You need both. The one from the stringified JSON is not picked
@@ -66,4 +65,11 @@ esbuild
66
65
  linaria({sourceMap: true, esbuildOptions: {sourcemap: "inline"}}),
67
66
  ],
68
67
  })
69
- .catch(() => process.exit(1));
68
+ .then(async (context) => {
69
+ if (production === false) {
70
+ context.watch();
71
+ } else {
72
+ await context.rebuild();
73
+ process.exit();
74
+ }
75
+ });
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import linaria from "@linaria/esbuild";
3
+ import linaria from "./linaria";
4
4
  import {vanillaExtractPlugin} from "@vanilla-extract/esbuild-plugin";
5
5
  import * as esbuild from "esbuild";
6
6
  import ImportGlobPlugin from "esbuild-plugin-import-glob";
@@ -13,8 +13,17 @@ const CACHE_KEY = `${process.cwd()}/node_modules/_reactivated/renderer.js`;
13
13
  const production = process.env.NODE_ENV === "production";
14
14
  const identifiers = production ? "short" : "debug";
15
15
 
16
+ const restartServer = () => {
17
+ if (server != null) {
18
+ server.close();
19
+ }
20
+
21
+ delete require.cache[CACHE_KEY];
22
+ server = require(CACHE_KEY).server;
23
+ };
24
+
16
25
  esbuild
17
- .build({
26
+ .context({
18
27
  stdin: {
19
28
  contents: `
20
29
  export {server} from "reactivated/dist/renderer";
@@ -33,14 +42,6 @@ esbuild
33
42
  // of the location of reactivated being in the cwd node_modules or
34
43
  // above as in monorepos.
35
44
  nodePaths: [`${process.cwd()}/node_modules`],
36
- watch:
37
- production === true
38
- ? false
39
- : {
40
- onRebuild: () => {
41
- restartServer();
42
- },
43
- },
44
45
  plugins: [
45
46
  ImportGlobPlugin(),
46
47
  // We manually pass in identifiers because the client is not
@@ -50,20 +51,23 @@ esbuild
50
51
  // settings.
51
52
  vanillaExtractPlugin({identifiers}),
52
53
  linaria({sourceMap: true}),
54
+ {
55
+ name: "restartServer",
56
+ setup: (build) => {
57
+ if (production === false) {
58
+ build.onEnd((result) => {
59
+ restartServer();
60
+ });
61
+ }
62
+ },
63
+ },
53
64
  ],
54
65
  })
55
- .then(() => {
66
+ .then(async (context) => {
56
67
  if (production === false) {
57
- restartServer();
68
+ context.watch();
69
+ } else {
70
+ await context.rebuild();
71
+ process.exit();
58
72
  }
59
- })
60
- .catch(() => process.exit(1));
61
-
62
- const restartServer = () => {
63
- if (server != null) {
64
- server.close();
65
- }
66
-
67
- delete require.cache[CACHE_KEY];
68
- server = require(CACHE_KEY).server;
69
- };
73
+ });
@@ -625,7 +625,7 @@ export const useFormSet = <T extends FieldMap>(options: {
625
625
 
626
626
  const addForm = () => {
627
627
  const {total_form_count} = formSet;
628
- type AdditionalForm = typeof formSet["forms"][number];
628
+ type AdditionalForm = (typeof formSet)["forms"][number];
629
629
 
630
630
  const extraForm = produce(formSet.empty_form, (draftState) => {
631
631
  for (const fieldName of draftState.iterator) {
package/src/generated.tsx CHANGED
@@ -1,4 +1,4 @@
1
- /* tslint:disable */
1
+ /* eslint-disable */
2
2
  /**
3
3
  * This file was automatically generated by json-schema-to-typescript.
4
4
  * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
@@ -22,6 +22,10 @@ export interface Types {
22
22
  | DjangoFormsWidgetsClearableFileInput
23
23
  | DjangoFormsWidgetsSelectDateWidget
24
24
  | DjangoFormsWidgetsSplitDateTimeWidget;
25
+ /**
26
+ * @minItems 3
27
+ * @maxItems 3
28
+ */
25
29
  Optgroup: [null, [ReactivatedTypesOptgroupMember], number];
26
30
  URLSchema: {
27
31
  [k: string]: ReactivatedTypesURL;
@@ -236,6 +240,10 @@ export interface DjangoFormsWidgetsSelectDateWidget {
236
240
  month: string | null;
237
241
  day: string | null;
238
242
  };
243
+ /**
244
+ * @minItems 3
245
+ * @maxItems 3
246
+ */
239
247
  subwidgets: [DjangoFormsWidgetsSelect, DjangoFormsWidgetsSelect, DjangoFormsWidgetsSelect];
240
248
  tag: "django.forms.widgets.SelectDateWidget";
241
249
  }
@@ -250,6 +258,10 @@ export interface DjangoFormsWidgetsSplitDateTimeWidget {
250
258
  "0": string | null;
251
259
  "1": string | null;
252
260
  };
261
+ /**
262
+ * @minItems 2
263
+ * @maxItems 2
264
+ */
253
265
  subwidgets: [DjangoFormsWidgetsDateInput, DjangoFormsWidgetsTimeInput];
254
266
  tag: "django.forms.widgets.SplitDateTimeWidget";
255
267
  }
package/src/generator.tsx CHANGED
@@ -147,7 +147,7 @@ export const {Form, FormSet, Widget, useForm, useFormSet, ManagementForm} = form
147
147
  `);
148
148
 
149
149
  // tslint:disable-next-line
150
- compile(types, "_Types").then((ts) => {
150
+ compile(types, "this is unused").then((ts) => {
151
151
  process.stdout.write("/* eslint-disable */\n");
152
152
  process.stdout.write(ts);
153
153
 
@@ -0,0 +1,150 @@
1
+ /**
2
+ * This file contains an esbuild loader for Linaria.
3
+ * It uses the transform.ts function to generate class names from source code,
4
+ * returns transformed code without template literals and attaches generated source maps
5
+ */
6
+
7
+ import fs from "fs";
8
+ import path from "path";
9
+
10
+ import type {Plugin, TransformOptions, Loader} from "esbuild";
11
+ import {transformSync} from "esbuild";
12
+
13
+ import type {PluginOptions, Preprocessor} from "@linaria/babel-preset";
14
+ import {slugify, transform} from "@linaria/babel-preset";
15
+
16
+ type EsbuildPluginOptions = {
17
+ sourceMap?: boolean;
18
+ preprocessor?: Preprocessor;
19
+ esbuildOptions?: TransformOptions;
20
+ } & Partial<PluginOptions>;
21
+
22
+ const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
23
+
24
+ export default function linaria({
25
+ sourceMap,
26
+ preprocessor,
27
+ esbuildOptions,
28
+ ...rest
29
+ }: EsbuildPluginOptions = {}): Plugin {
30
+ let options = esbuildOptions;
31
+ return {
32
+ name: "linaria",
33
+ setup(build) {
34
+ const cssLookup = new Map<string, string>();
35
+
36
+ const asyncResolve = async (
37
+ token: string,
38
+ importer: string,
39
+ ): Promise<string> => {
40
+ const context = path.isAbsolute(importer)
41
+ ? path.dirname(importer)
42
+ : path.join(process.cwd(), path.dirname(importer));
43
+
44
+ const result = await build.resolve(token, {
45
+ kind: "entry-point",
46
+ resolveDir: context,
47
+ });
48
+
49
+ if (result.errors.length > 0) {
50
+ throw new Error(`Cannot resolve ${token}`);
51
+ }
52
+
53
+ return result.path;
54
+ };
55
+
56
+ build.onResolve({filter: /\.linaria\.css$/}, (args) => {
57
+ return {
58
+ namespace: "linaria",
59
+ path: args.path,
60
+ };
61
+ });
62
+
63
+ build.onLoad({filter: /.*/, namespace: "linaria"}, (args) => {
64
+ return {
65
+ contents: cssLookup.get(args.path),
66
+ loader: "css",
67
+ resolveDir: path.basename(args.path),
68
+ };
69
+ });
70
+
71
+ build.onLoad({filter: /\.(js|jsx|ts|tsx)$/}, async (args) => {
72
+ const rawCode = fs.readFileSync(args.path, "utf8");
73
+ const {ext, name: filename} = path.parse(args.path);
74
+ const loader = ext.replace(/^\./, "") as Loader;
75
+
76
+ if (nodeModulesRegex.test(args.path)) {
77
+ return {
78
+ loader,
79
+ contents: rawCode,
80
+ };
81
+ }
82
+
83
+ if (!options) {
84
+ options = {};
85
+ if ("jsxFactory" in build.initialOptions) {
86
+ options.jsxFactory = build.initialOptions.jsxFactory;
87
+ }
88
+ if ("jsxFragment" in build.initialOptions) {
89
+ options.jsxFragment = build.initialOptions.jsxFragment;
90
+ }
91
+ }
92
+
93
+ const transformed = transformSync(rawCode, {
94
+ ...options,
95
+ sourcefile: args.path,
96
+ sourcemap: sourceMap,
97
+ loader,
98
+ });
99
+ let {code} = transformed;
100
+
101
+ if (sourceMap) {
102
+ const esbuildMap = Buffer.from(transformed.map).toString("base64");
103
+ code += `/*# sourceMappingURL=data:application/json;base64,${esbuildMap}*/`;
104
+ }
105
+
106
+ const result = await transform(
107
+ code,
108
+ {
109
+ filename: args.path,
110
+ preprocessor,
111
+ pluginOptions: rest,
112
+ },
113
+ asyncResolve,
114
+ );
115
+
116
+ if (!result.cssText) {
117
+ return {
118
+ contents: code,
119
+ loader,
120
+ resolveDir: path.dirname(args.path),
121
+ };
122
+ }
123
+
124
+ let {cssText} = result;
125
+
126
+ const slug = slugify(cssText);
127
+ const cssFilename = `${filename}_${slug}.linaria.css`;
128
+
129
+ let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;
130
+
131
+ if (sourceMap && result.cssSourceMapText) {
132
+ const map = Buffer.from(result.cssSourceMapText).toString("base64");
133
+ cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
134
+ const linariaMap = Buffer.from(
135
+ JSON.stringify(result.sourceMap),
136
+ ).toString("base64");
137
+ contents += `/*# sourceMappingURL=data:application/json;base64,${linariaMap}*/`;
138
+ }
139
+
140
+ cssLookup.set(cssFilename, cssText);
141
+
142
+ return {
143
+ contents,
144
+ loader,
145
+ resolveDir: path.dirname(args.path),
146
+ };
147
+ });
148
+ },
149
+ };
150
+ }