bridgetown-core 1.3.0.beta1 → 1.3.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9176399e9b750178476e2d57edb346989426407d5d40e8958c5be3901626f77f
4
- data.tar.gz: a5130e5511c64acba6e6ee619a7529b49415e1c25b3e056cf4e709c4d78361da
3
+ metadata.gz: ec81158ce54460fb44c4296bae6c3eb75c95c627492c6fe5891cbd853089a13c
4
+ data.tar.gz: e22e4e4cfd9b4c27a5eefefd1670e43c99badb7eb9c8be96105b47e024324543
5
5
  SHA512:
6
- metadata.gz: 849bff55f1997483ce24f67536daec7bdd53ff016d7e4ab8937b0184892680eb59f159d3a3d26c22fbc63ef63486ddd1b793943cd21fead6c281f0d2d9698f69
7
- data.tar.gz: e5c317edb3ae4e232cd2a56c885b44af5375d7daeff71f385e620d402cbe57c68cf32fdc6eb13508bb92e3e8dff254cf53e59f56790631692eee092c6eaa0463
6
+ metadata.gz: 6130dec47320b9b66406afbb6e98e5851ceba1664292c37be8d02a800c9e95a6c9678ccbc5c822dc2f64497e0b9b0826c0956dd72ab81c2526b9fb499b3d13a5
7
+ data.tar.gz: ac1d0032d102186ae07d41997bd29541bf96eb3e7aee7aa6ca25df8da5b3cebef18ebb7cb3d51c1ef58270df68c65d126271b55bb822f8fdd046927ccfee68b5
@@ -48,6 +48,9 @@ module Bridgetown
48
48
 
49
49
  if !Bridgetown.env.production? &&
50
50
  !config_options[:skip_frontend] && config_options["using_puma"]
51
+ if Bridgetown::Utils.frontend_bundler_type(config_options[:root_dir]) == :esbuild
52
+ Bridgetown::Utils.update_esbuild_autogenerated_config config_options
53
+ end
51
54
  require "rake"
52
55
  Rake.with_application do |rake|
53
56
  rake.load_rakefile
@@ -16,7 +16,6 @@ module Bridgetown
16
16
  I18n.reload! # make sure any locale files get read again
17
17
  Bridgetown::Hooks.trigger :site, :pre_reload, site
18
18
  Bridgetown::Hooks.clear_reloadable_hooks
19
- site.plugin_manager.reload_plugin_files
20
19
  site.loaders_manager.reload_loaders
21
20
  Bridgetown::Hooks.trigger :site, :post_reload, site
22
21
 
@@ -1,8 +1,5 @@
1
1
  const build = require("./config/esbuild.defaults.js")
2
2
 
3
- // Update this if you need to configure a destination folder other than `output`
4
- const outputFolder = "output"
5
-
6
3
  // You can customize this as you wish, perhaps to add new esbuild plugins.
7
4
  //
8
5
  // ```
@@ -24,13 +21,23 @@ const outputFolder = "output"
24
21
  // You can also support custom base_path deployments via changing `publicPath`.
25
22
  //
26
23
  // ```
27
- // const esbuildOptions = { publicPath: "/my_subfolder/_bridgetown/static" }
24
+ // const esbuildOptions = {
25
+ // publicPath: "/my_subfolder/_bridgetown/static",
26
+ // ...
27
+ // }
28
28
  // ```
29
29
 
30
30
  /**
31
31
  * @typedef { import("esbuild").BuildOptions } BuildOptions
32
32
  * @type {BuildOptions}
33
33
  */
34
- const esbuildOptions = {}
34
+ const esbuildOptions = {
35
+ plugins: [
36
+ // add new plugins here...
37
+ ],
38
+ globOptions: {
39
+ excludeFilter: /\.(dsd|lit)\.css$/
40
+ }
41
+ }
35
42
 
36
- build(outputFolder, esbuildOptions)
43
+ build(esbuildOptions)
@@ -8,6 +8,14 @@
8
8
  //
9
9
  // Shipped with Bridgetown v<%= Bridgetown::VERSION %>
10
10
 
11
+ // DO NOT MANUALLY EDIT THIS CONFIGURATION:
12
+ const autogeneratedBridgetownConfig = {
13
+ "source": "src",
14
+ "destination": "output",
15
+ "componentsDir": "_components",
16
+ "islandsDir": "_islands"
17
+ }
18
+
11
19
  const path = require("path")
12
20
  const fsLib = require("fs")
13
21
  const fs = fsLib.promises
@@ -41,7 +49,7 @@ if (moduleAvailable("sass")) {
41
49
  // Glob plugin derived from:
42
50
  // https://github.com/thomaschaaf/esbuild-plugin-import-glob
43
51
  // https://github.com/xiaohui-zhangxh/jsbundling-rails/commit/b15025dcc20f664b2b0eb238915991afdbc7cb58
44
- const importGlobPlugin = () => ({
52
+ const importGlobPlugin = (options, bridgetownConfig) => ({
45
53
  name: "import-glob",
46
54
  setup: (build) => {
47
55
  build.onResolve({ filter: /\*/ }, async (args) => {
@@ -49,7 +57,9 @@ const importGlobPlugin = () => ({
49
57
  return; // Ignore unresolvable paths
50
58
  }
51
59
 
52
- const adjustedPath = args.path.replace(/^bridgetownComponents\//, "../../src/_components/")
60
+ const adjustedPath = args.path
61
+ .replace(/^\$components\/\*\*/, `../../${bridgetownConfig.source}/${bridgetownConfig.componentsDir}/**`)
62
+ .replace(/^bridgetownComponents\//, `../../${bridgetownConfig.source}/${bridgetownConfig.componentsDir}/`) // legacy
53
63
 
54
64
  return {
55
65
  path: adjustedPath,
@@ -64,7 +74,11 @@ const importGlobPlugin = () => ({
64
74
  build.onLoad({ filter: /.*/, namespace: "import-glob" }, async (args) => {
65
75
  const files = glob.sync(args.pluginData.path, {
66
76
  cwd: args.pluginData.resolveDir,
67
- }).sort()
77
+ })
78
+ .filter(module => options.excludeFilter ? !options.excludeFilter.test(module) : true)
79
+ .sort()
80
+ .map(module => module.replace(`../../${bridgetownConfig.source}/${bridgetownConfig.componentsDir}/`, "$components/"))
81
+ .map(module => module.match(/^[a-zA-Z0-9]/) ? `./${module}` : module)
68
82
 
69
83
  const importerCode = `
70
84
  ${files
@@ -72,7 +86,7 @@ const importGlobPlugin = () => ({
72
86
  .join(';')}
73
87
  const modules = {${files
74
88
  .map((module, index) => `
75
- "${module.replace("../../src/_components/", "")}": module${index},`)
89
+ "${module.replace("$components/", "")}": module${index},`)
76
90
  .join("")}
77
91
  };
78
92
  export default modules;
@@ -187,7 +201,7 @@ const sassPlugin = (options) => ({
187
201
  })
188
202
 
189
203
  // Set up defaults and generate frontend bundling manifest file
190
- const bridgetownPreset = (outputFolder) => ({
204
+ const bridgetownPreset = (bridgetownConfig) => ({
191
205
  name: "bridgetownPreset",
192
206
  async setup(build) {
193
207
  // Ensure any imports anywhere starting with `/` are left verbatim
@@ -210,8 +224,10 @@ const bridgetownPreset = (outputFolder) => ({
210
224
  const manifest = {}
211
225
  const entrypoints = []
212
226
 
213
- // We don't need `frontend/` cluttering up everything
214
- const stripPrefix = (str) => str.replace(/^frontend\//, "")
227
+ // Clean up entrypoint naming
228
+ const stripPrefix = (str) => str
229
+ .replace(/^frontend\//, "")
230
+ .replace(RegExp(String.raw`^${bridgetownConfig.source}\/${bridgetownConfig.islandsDir}\/`), "islands/")
215
231
 
216
232
  // For calculating the file size of bundle output
217
233
  const fileSize = (path) => {
@@ -220,11 +236,12 @@ const bridgetownPreset = (outputFolder) => ({
220
236
  return (size / Math.pow(1024, i)).toFixed(2) * 1 + ['B', 'KB', 'MB', 'GB', 'TB'][i]
221
237
  }
222
238
 
239
+ const pathShortener = new RegExp(String.raw`^${bridgetownConfig.destination}\/_bridgetown\/static\/`, "g")
240
+
223
241
  // Let's loop through all the various outputs
224
242
  for (const key in result.metafile.outputs) {
225
243
  const value = result.metafile.outputs[key]
226
244
  const inputs = Object.keys(value.inputs)
227
- const pathShortener = new RegExp(`^${outputFolder}\\/_bridgetown\\/static\\/`, "g")
228
245
  const outputPath = key.replace(pathShortener, "")
229
246
 
230
247
  if (value.entryPoint) {
@@ -256,23 +273,43 @@ const bridgetownPreset = (outputFolder) => ({
256
273
  }
257
274
  })
258
275
 
276
+ const bridgetownConfigured = (bridgetownConfig, outputFolder) => {
277
+ bridgetownConfig = {...autogeneratedBridgetownConfig, ...bridgetownConfig}
278
+ if (outputFolder) bridgetownConfig.destination = outputFolder
279
+
280
+ return bridgetownConfig
281
+ }
282
+
259
283
  // Load the PostCSS config from postcss.config.js or whatever else is a supported location/format
260
284
  const postcssrc = require("postcss-load-config")
261
285
 
262
- module.exports = async (outputFolder, esbuildOptions) => {
286
+ module.exports = async (esbuildOptions, ...args) => {
287
+ let outputFolder;
288
+ if (typeof esbuildOptions === "string") { // legacy syntax where first argument is output folder
289
+ outputFolder = esbuildOptions
290
+ esbuildOptions = args[0]
291
+ }
292
+ const bridgetownConfig = bridgetownConfigured(esbuildOptions.bridgetownConfig, outputFolder)
293
+
263
294
  esbuildOptions.plugins = esbuildOptions.plugins || []
264
295
  // Add the PostCSS & glob plugins to the top of the plugin stack
265
296
  const postCssConfig = await postcssrc()
266
297
  esbuildOptions.plugins.unshift(importPostCssPlugin(postCssConfig, esbuildOptions.postCssPluginConfig || {}))
267
298
  if (esbuildOptions.postCssPluginConfig) delete esbuildOptions.postCssPluginConfig
268
- esbuildOptions.plugins.unshift(importGlobPlugin())
299
+ // Add the Glob plugin
300
+ esbuildOptions.plugins.unshift(importGlobPlugin(esbuildOptions.globOptions || {}, bridgetownConfig))
301
+ if (esbuildOptions.globOptions) delete esbuildOptions.globOptions
269
302
  // Add the Sass plugin
270
303
  esbuildOptions.plugins.push(sassPlugin(esbuildOptions.sassOptions || {}))
304
+ if (esbuildOptions.sassOptions) delete esbuildOptions.sassOptions
271
305
  // Add the Bridgetown preset
272
- esbuildOptions.plugins.push(bridgetownPreset(outputFolder))
306
+ esbuildOptions.plugins.push(bridgetownPreset(bridgetownConfig))
307
+ if (esbuildOptions.bridgetownConfig) delete esbuildOptions.bridgetownConfig
273
308
 
274
- // esbuild, take it away!
275
- require("esbuild").build({
309
+ const esbuild = require("esbuild")
310
+ const islands = glob.sync(`./${bridgetownConfig.source}/${bridgetownConfig.islandsDir}/*.{js,js.rb}`).map(item => `./${item}`)
311
+
312
+ esbuild.context({
276
313
  bundle: true,
277
314
  loader: {
278
315
  ".jpg": "file",
@@ -285,16 +322,25 @@ module.exports = async (outputFolder, esbuildOptions) => {
285
322
  ".eot": "file",
286
323
  },
287
324
  resolveExtensions: [".tsx", ".ts", ".jsx", ".js", ".css", ".scss", ".sass", ".json", ".js.rb"],
288
- nodePaths: ["frontend/javascript", "frontend/styles"],
289
- watch: process.argv.includes("--watch"),
290
325
  minify: process.argv.includes("--minify"),
291
326
  sourcemap: true,
292
- target: "es2016",
293
- entryPoints: ["./frontend/javascript/index.js"],
327
+ target: "es2020",
328
+ entryPoints: ["./frontend/javascript/index.js", ...islands],
294
329
  entryNames: "[dir]/[name].[hash]",
295
- outdir: path.join(process.cwd(), `${outputFolder}/_bridgetown/static`),
330
+ outdir: path.join(process.cwd(), `${bridgetownConfig.destination}/_bridgetown/static`),
296
331
  publicPath: "/_bridgetown/static",
297
332
  metafile: true,
298
333
  ...esbuildOptions,
334
+ }).then(context => {
335
+ if (process.argv.includes("--watch")) {
336
+ // Enable watch mode
337
+ context.watch()
338
+ } else {
339
+ // Build once and exit if not in watch mode
340
+ context.rebuild().then(result => {
341
+ context.dispose()
342
+ })
343
+ }
344
+ process.on('SIGINT', () => process.exit())
299
345
  }).catch(() => process.exit(1))
300
346
  }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "paths": {
5
+ "$styles/*": ["./frontend/styles/*"],
6
+ "$javascript/*": ["./frontend/javascript/*"],
7
+ "$components/*": ["./src/_components/*"]
8
+ }
9
+ },
10
+ }
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  template "esbuild.defaults.js.erb", "config/esbuild.defaults.js"
4
+ copy_file "jsconfig.json"
4
5
  copy_file "esbuild.config.js", force: true
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  template "esbuild.defaults.js.erb", "config/esbuild.defaults.js", force: true
4
+ copy_file "jsconfig.json"
4
5
  say "🎉 esbuild configuration updated successfully!"
6
+ say "You may need to add `$styles/` to the front of your main CSS imports."
7
+ say "See https://www.bridgetownrb.com/docs/frontend-assets#esbuild-setup for details."
@@ -33,8 +33,8 @@ module Bridgetown
33
33
  "collections_dir" => "",
34
34
  "cache_dir" => ".bridgetown-cache",
35
35
  "layouts_dir" => "_layouts",
36
- "data_dir" => "_data",
37
36
  "components_dir" => "_components",
37
+ "islands_dir" => "_islands",
38
38
  "partials_dir" => "_partials",
39
39
  "collections" => {},
40
40
  "taxonomies" => {
@@ -44,7 +44,6 @@ module Bridgetown
44
44
  "eager_load_paths" => [],
45
45
  "autoloader_collapsed_paths" => [],
46
46
  "additional_watch_paths" => [],
47
- "plugins_use_zeitwerk" => true,
48
47
 
49
48
  # Handling Reading
50
49
  "include" => [".htaccess", "_redirects", ".well-known"],
@@ -335,30 +334,32 @@ module Bridgetown
335
334
  self[:source] = File.expand_path(self[:source], self[:root_dir])
336
335
  self[:destination] = File.expand_path(self[:destination], self[:root_dir])
337
336
 
338
- if self[:plugins_use_zeitwerk]
339
- autoload_paths.unshift({
340
- path: self[:plugins_dir],
341
- eager: true,
342
- })
343
- end
337
+ autoload_paths.unshift({
338
+ path: self[:plugins_dir],
339
+ eager: true,
340
+ })
341
+ autoload_paths.unshift({
342
+ path: File.expand_path(self[:islands_dir], self[:source]),
343
+ eager: true,
344
+ })
344
345
  end
345
346
 
346
347
  autoload_paths.map! do |load_path|
347
348
  if load_path.is_a?(Hash)
348
- expanded = File.expand_path(load_path[:path], root_dir)
349
+ expanded = File.expand_path(load_path[:path], self[:root_dir])
349
350
  self[:eager_load_paths] << expanded if load_path[:eager]
350
351
  next expanded
351
352
  end
352
353
 
353
- File.expand_path(load_path, root_dir)
354
+ File.expand_path(load_path, self[:root_dir])
354
355
  end
355
356
 
356
357
  autoloader_collapsed_paths.map! do |collapsed_path|
357
- File.expand_path(collapsed_path, root_dir)
358
+ File.expand_path(collapsed_path, self[:root_dir])
358
359
  end
359
360
 
360
361
  additional_watch_paths.map! do |collapsed_path|
361
- File.expand_path(collapsed_path, root_dir)
362
+ File.expand_path(collapsed_path, self[:root_dir])
362
363
  end
363
364
 
364
365
  self
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ say_status "is-land", "Installing <is-land>..."
4
+
5
+ run "yarn add @11ty/is-land"
6
+
7
+ javascript_import do
8
+ <<~JS
9
+ import "@11ty/is-land/is-land.js"
10
+ import "@11ty/is-land/is-land-autoinit.js"
11
+ JS
12
+ end
13
+
14
+ say_status "is-land", "<is-land> is now configured!"
15
+ say 'For further reading, check out "https://www.bridgetownrb.com/docs/islands"', :blue
@@ -1 +1 @@
1
- import components from "bridgetownComponents/**/*.{lit.js,lit.js.rb}"
1
+ import components from "$components/**/*.{lit.js,lit.js.rb}"
@@ -11,9 +11,9 @@ end
11
11
 
12
12
  say_status :lit, "Installing Lit + SSR Plugin..."
13
13
 
14
- add_gem "bridgetown-lit-renderer"
14
+ add_gem "bridgetown-lit-renderer", version: "2.1.0.beta2"
15
15
 
16
- run "yarn add lit esbuild-plugin-lit-css bridgetown-lit-renderer"
16
+ run "yarn add lit esbuild-plugin-lit-css bridgetown-lit-renderer@2.1.0-beta2"
17
17
 
18
18
  copy_file in_templates_dir("lit-ssr.config.js"), "config/lit-ssr.config.js"
19
19
  copy_file in_templates_dir("lit-components-entry.js"), "config/lit-components-entry.js"
@@ -27,45 +27,13 @@ insert_into_file "esbuild.config.js",
27
27
  JS
28
28
  end
29
29
 
30
- found_match = false
31
- gsub_file "esbuild.config.js", %r{const esbuildOptions = {}\n} do |_match|
32
- found_match = true
33
-
34
- <<~JS
35
- const esbuildOptions = {
36
- plugins: [...plugins],
37
- // Uncomment the following to opt into `.global.css` & `.lit.css` nomenclature.
38
- // Read https://www.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
39
- /*
40
- postCssPluginConfig: {
41
- filter: /(?:index|\\.global)\\.css$/,
42
- },
43
- */
44
- }
30
+ insert_into_file "esbuild.config.js",
31
+ after: " plugins: [" do
32
+ <<-JS
33
+ ...plugins,
45
34
  JS
46
35
  end
47
36
 
48
- unless found_match
49
- insert_into_file "esbuild.config.js",
50
- after: 'const { plugins } = require("./config/esbuild-plugins.js")' do
51
- <<~JS
52
-
53
- // TODO: You will manually need to move any plugins below you wish to share with
54
- // Lit SSR into the `config/esbuild-plugins.js` file.
55
- // Then add `...plugins` as an item in your plugins array.
56
- //
57
- // You might also want to include the following in your esbuild config to opt into
58
- // `.global.css` & `.lit.css` nomenclature.
59
- // Read https://www.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
60
- /*
61
- postCssPluginConfig: {
62
- filter: /(?:index|\\.global)\\.css$/,
63
- },
64
- */
65
- JS
66
- end
67
- end
68
-
69
37
  copy_file in_templates_dir("happy-days.lit.js"), "src/_components/happy-days.lit.js"
70
38
 
71
39
  javascript_import do
@@ -74,24 +42,11 @@ javascript_import do
74
42
  JS
75
43
  end
76
44
 
77
- insert_into_file "frontend/javascript/index.js",
78
- before: 'import components from "bridgetownComponents/**/*.{js,jsx,js.rb,css}"' do
79
- <<~JS
80
- // To opt into `.global.css` & `.lit.css` nomenclature, change the `css` extension below to `global.css`.
81
- // Read https://www.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
82
- JS
83
- end
84
-
85
45
  add_initializer :"bridgetown-lit-renderer"
86
46
 
87
- if found_match
88
- say_status :lit, "Lit is now configured!"
89
- say_status :lit,
90
- "The `config/esbuild-plugins.js` file will let you add full-stack plugins in future."
91
- else
92
- say_status :lit, "Lit is just about configured!"
93
- say_status :lit, "You will need to edit `esbuild.config.js` to finish setting up the plugin."
94
- end
47
+ say_status :lit, "Lit is now configured!"
48
+ say_status :lit,
49
+ "The `config/esbuild-plugins.js` file will let you add full-stack plugins in future."
95
50
 
96
51
  say "Check out the example `happy-days.lit.js` file in `src/_components`", :blue
97
52
  say 'For further reading, check out "https://www.bridgetownrb.com/docs/components/lit"', :blue
@@ -0,0 +1,10 @@
1
+ # See docs on Ruby2JS options here: https://www.ruby2js.com/docs/options
2
+
3
+ preset
4
+
5
+ filter :camelCase
6
+ filter :lit
7
+
8
+ eslevel 2022
9
+
10
+ autoexports :default
@@ -11,57 +11,29 @@ end
11
11
 
12
12
  say_status :ruby2js, "Installing Ruby2JS..."
13
13
 
14
+ add_gem "ruby2js"
14
15
  run "yarn add -D @ruby2js/esbuild-plugin"
15
16
 
16
- found_match = false
17
- gsub_file "esbuild.config.js", %r{const esbuildOptions = {}\n} do |_match|
18
- found_match = true
19
-
17
+ insert_into_file "esbuild.config.js",
18
+ after: 'const build = require("./config/esbuild.defaults.js")' do
20
19
  <<~JS
21
- const ruby2js = require("@ruby2js/esbuild-plugin")
22
20
 
23
- const esbuildOptions = {
24
- plugins: [
25
- // See docs on Ruby2JS options here: https://www.ruby2js.com/docs/options
26
- ruby2js({
27
- eslevel: 2022,
28
- autoexports: "default",
29
- filters: ["camelCase", "functions", "lit", "esm", "return"]
30
- })
31
- ]
32
- }
21
+ const ruby2js = require("@ruby2js/esbuild-plugin")
33
22
  JS
34
23
  end
35
24
 
36
- unless found_match
37
- insert_into_file "esbuild.config.js",
38
- after: 'const build = require("./config/esbuild.defaults.js")' do
39
- <<~JS
40
-
41
- const ruby2js = require("@ruby2js/esbuild-plugin")
42
-
43
- // TODO: Uncomment and move the following into your plugins array:
44
- //
45
- // ruby2js({
46
- // eslevel: 2022,
47
- // autoexports: "default",
48
- // filters: ["camelCase", "functions", "lit", "esm", "return"]
49
- // })
50
- //
51
- // See docs on Ruby2JS options here: https://www.ruby2js.com/docs/options
52
-
53
- JS
54
- end
25
+ insert_into_file "esbuild.config.js",
26
+ after: " plugins: [" do
27
+ <<-JS
28
+ ruby2js(),
29
+ JS
55
30
  end
56
31
 
32
+ copy_file in_templates_dir("ruby2js.rb"), "config/ruby2js.rb"
57
33
  copy_file in_templates_dir("hello_world.js.rb"), "src/_components/hello_world.js.rb"
58
34
 
59
- if found_match
60
- say_status :ruby2js, "Ruby2JS is now configured!"
61
- else
62
- say_status :ruby2js, "Ruby2JS is just about configured!"
63
- say_status :ruby2js, "You will need to edit `esbuild.config.js` to finish setting up the plugin."
64
- end
35
+ say_status :ruby2js, "Ruby2JS is now configured!"
65
36
 
66
37
  say "Check out the example `hello_world.js.rb` file in `src/_components`", :blue
38
+ say "Ruby2JS configuration options are saved in `config/ruby2js.rb`", :blue
67
39
  say 'For further reading, check out "https://www.ruby2js.com"', :blue
@@ -3,6 +3,7 @@
3
3
  say_status :turbo, "Installing Turbo..."
4
4
 
5
5
  run("yarn add @hotwired/turbo")
6
+ run("yarn add turbo-shadow")
6
7
 
7
8
  say_status :turbo, 'Adding Turbo to "frontend/javascript/index.js"...', :magenta
8
9
 
@@ -10,11 +11,17 @@ javascript_import do
10
11
  <<~JS
11
12
  import * as Turbo from "@hotwired/turbo"
12
13
 
13
- // Uncomment the line below to add transition animations when Turbo navigates.
14
- // We recommend adding <meta name="turbo-cache-control" content="no-preview" />
15
- // to your HTML head if you turn on transitions. Use data-turbo-transition="false"
16
- // on your <main> element for pages where you don't want any transition animation.
17
- //
14
+ /**
15
+ * Adds support for declarative shadow DOM. Requires your HTML <head> to include:
16
+ * `<meta name="turbo-cache-control" content="no-cache" />`
17
+ */
18
+ import * as TurboShadow from "turbo-shadow"
19
+
20
+ /**
21
+ * Uncomment the line below to add transition animations when Turbo navigates.
22
+ * Use data-turbo-transition="false" on your <main> element for pages where
23
+ * you don't want any transition animation.
24
+ */
18
25
  // import "./turbo_transitions.js"
19
26
  JS
20
27
  end
@@ -22,5 +29,8 @@ end
22
29
  copy_file in_templates_dir("turbo_transitions.js"), "frontend/javascript/turbo_transitions.js"
23
30
 
24
31
  say_status :turbo, "Turbo successfully added!", :magenta
25
- say_status :turbo, "Take a look in your index.js file for optional animation setup.", :blue
26
- say_status :turbo, 'For further reading, check out "https://turbo.hotwired.dev/"', :blue
32
+ say_status :turbo, "For declarative shadow DOM support, you will need to update", :blue
33
+ say_status :turbo, "your HTML <head> to add the following code:", :blue
34
+ say %(<meta name="turbo-cache-control" content="no-cache" />)
35
+ say_status :turbo, "Check out your index.js file for optional animation setup.", :blue
36
+ say_status :turbo, 'For further reading, visit "https://turbo.hotwired.dev/"', :blue
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Filters
5
+ module LocalizationFilters
6
+ def l(input)
7
+ I18n.l(input.to_s)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -135,6 +135,14 @@ module Bridgetown
135
135
  I18n.send :t, *args, **kwargs
136
136
  end
137
137
 
138
+ # Forward all arguments to I18n.l method
139
+ #
140
+ # @return [String] the localized string
141
+ # @see I18n
142
+ def l(*args, **kwargs)
143
+ I18n.send :l, *args, **kwargs
144
+ end
145
+
138
146
  # For template contexts where ActiveSupport's output safety is loaded, we
139
147
  # can ensure a string has been marked safe
140
148
  #
@@ -221,6 +229,32 @@ module Bridgetown
221
229
  end
222
230
  end
223
231
 
232
+ def dsd(input = nil, &block)
233
+ tmpl_content = block.nil? ? input.to_s : view.capture(&block)
234
+
235
+ Bridgetown::Utils.dsd_tag(tmpl_content)
236
+ end
237
+
238
+ def dsd_style
239
+ tmpl_path = caller_locations(1, 2).find do |loc|
240
+ loc.label.include?("method_missing").!
241
+ end&.path
242
+
243
+ return unless tmpl_path # virtually guaranteed not to happen
244
+
245
+ tmpl_basename = File.basename(tmpl_path, ".*")
246
+ style_path = File.join(File.dirname(tmpl_path), "#{tmpl_basename}.dsd.css")
247
+
248
+ unless File.file?(style_path)
249
+ raise Bridgetown::Errors::FatalException, "Missing stylesheet at #{style_path}"
250
+ end
251
+
252
+ style_tag = site.tmp_cache["dsd_style:#{style_path}"] ||=
253
+ "<style>#{File.read(style_path)}</style>"
254
+
255
+ style_tag.html_safe
256
+ end
257
+
224
258
  private
225
259
 
226
260
  # Covert an underscored value into a dashed string.
@@ -206,30 +206,6 @@ module Bridgetown
206
206
  sorted_plugin_files.each do |plugin_file|
207
207
  self.class.add_registered_plugin plugin_file
208
208
  end
209
- next if site.config[:plugins_use_zeitwerk]
210
-
211
- Deprecator.deprecation_message(
212
- "The `plugins_use_zeitwerk' configuration option will be removed in the next version " \
213
- "of Bridgetown (aka will be permanently set to \"true\")"
214
- )
215
- Bridgetown::Utils::RequireGems.require_with_graceful_fail(sorted_plugin_files)
216
- end
217
- end
218
-
219
- # Reloads .rb plugin files via the watcher
220
- # DEPRECATED (not necessary with Zeitwerk)
221
- #
222
- # @return [void]
223
- def reload_plugin_files
224
- return if site.config[:plugins_use_zeitwerk]
225
-
226
- plugins_path.each do |plugin_search_path|
227
- plugin_files = Utils.safe_glob(plugin_search_path, File.join("**", "*.rb"))
228
- Array(plugin_files).each do |name|
229
- Bridgetown.logger.debug "Reloading:", name.to_s
230
- self.class.add_registered_plugin name
231
- load name
232
- end
233
209
  end
234
210
  end
235
211
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Tags
5
+ class DSDTag < Liquid::Block
6
+ def render(_context)
7
+ template_content = super
8
+
9
+ Bridgetown::Utils.dsd_tag(template_content)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ Liquid::Template.register_tag("dsd", Bridgetown::Tags::DSDTag)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Tags
5
+ class LocalizationTag < Liquid::Tag
6
+ def render(_context)
7
+ key = @markup.strip
8
+ I18n.l(key)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ Liquid::Template.register_tag("l", Bridgetown::Tags::LocalizationTag)
@@ -29,6 +29,8 @@ module Bridgetown
29
29
  loop do
30
30
  line = rd.gets
31
31
  line.to_s.lines.map(&:chomp).each do |message|
32
+ next if name == "Frontend" && %r{ELIFECYCLE.*?Command failed}.match?(message)
33
+
32
34
  output = +""
33
35
  output << with_color(color, "[#{name}] ") if color
34
36
  output << message
@@ -62,6 +62,9 @@ module Bridgetown
62
62
  end
63
63
  loader.enable_reloading if reloading_enabled?(load_path)
64
64
  loader.ignore(File.join(load_path, "**", "*.js.rb"))
65
+ loader.ignore(
66
+ File.join(File.expand_path(config[:islands_dir], config[:source]), "routes")
67
+ )
65
68
  config.autoloader_collapsed_paths.each do |collapsed_path|
66
69
  next unless collapsed_path.starts_with?(load_path)
67
70
 
@@ -412,7 +412,7 @@ module Bridgetown
412
412
  end&.last
413
413
  end
414
414
 
415
- return log_frontend_asset_error(site, asset_type) if asset_path.nil?
415
+ return log_frontend_asset_error(site, "`#{asset_type}' asset") if asset_path.nil?
416
416
 
417
417
  static_frontend_path site, [asset_path]
418
418
  end
@@ -429,14 +429,16 @@ module Bridgetown
429
429
 
430
430
  def log_frontend_asset_error(site, asset_type)
431
431
  site.data[:__frontend_asset_errors] ||= {}
432
- site.data[:__frontend_asset_errors][asset_type] ||=
432
+ site.data[:__frontend_asset_errors][asset_type] ||= begin
433
+ Bridgetown.logger.warn("#{frontend_bundler_type}:", "The #{asset_type} could not be found.")
433
434
  Bridgetown.logger.warn(
434
435
  "#{frontend_bundler_type}:",
435
- "There was an error parsing your #{asset_type} file. \
436
- Please check your #{asset_type} file for any errors."
436
+ "Double-check your frontend config or re-run `bin/bridgetown frontend:build'"
437
437
  )
438
+ true
439
+ end
438
440
 
439
- "MISSING_#{frontend_bundler_type.upcase}_MANIFEST_FILE"
441
+ "MISSING_#{frontend_bundler_type.upcase}_ASSET"
440
442
  end
441
443
 
442
444
  def frontend_bundler_type(cwd = Dir.pwd)
@@ -449,6 +451,27 @@ module Bridgetown
449
451
  end
450
452
  end
451
453
 
454
+ def update_esbuild_autogenerated_config(config)
455
+ defaults_file = File.join(config[:root_dir], "config", "esbuild.defaults.js")
456
+ return unless File.exist?(defaults_file)
457
+
458
+ config_hash = {
459
+ source: Pathname.new(config[:source]).relative_path_from(config[:root_dir]),
460
+ destination: Pathname.new(config[:destination]).relative_path_from(config[:root_dir]),
461
+ componentsDir: config[:components_dir],
462
+ islandsDir: config[:islands_dir],
463
+ }
464
+
465
+ defaults_file_contents = File.read(defaults_file)
466
+ File.write(
467
+ defaults_file,
468
+ defaults_file_contents.sub(
469
+ %r{(const autogeneratedBridgetownConfig = ){\n.*?}}m,
470
+ "\\1#{JSON.pretty_generate config_hash}"
471
+ )
472
+ )
473
+ end
474
+
452
475
  def default_github_branch_name(repo_url)
453
476
  repo_match = Bridgetown::Commands::Actions::GITHUB_REPO_REGEX.match(repo_url)
454
477
  api_endpoint = "https://api.github.com/repos/#{repo_match[1]}"
@@ -523,6 +546,12 @@ module Bridgetown
523
546
  end
524
547
  end
525
548
 
549
+ def dsd_tag(input, shadow_root_mode: :open)
550
+ raise ArgumentError unless [:open, :closed].include? shadow_root_mode
551
+
552
+ %(<template shadowrootmode="#{shadow_root_mode}">#{input}</template>).html_safe
553
+ end
554
+
526
555
  private
527
556
 
528
557
  def merge_values(target, overwrite)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "1.3.0.beta1"
4
+ VERSION = "1.3.0.beta3"
5
5
  CODE_NAME = "Kelly Butte"
6
6
  end
@@ -55,7 +55,7 @@ module Bridgetown
55
55
  # Start a listener to watch for changes and call {#reload_site}
56
56
  #
57
57
  # @param (see #watch)
58
- def listen(site, options)
58
+ def listen(site, options) # rubocop:disable Metrics/MethodLength
59
59
  bundling_path = site.frontend_bundling_path
60
60
  FileUtils.mkdir_p(bundling_path)
61
61
  Listen.to(
@@ -66,12 +66,17 @@ module Bridgetown
66
66
  force_polling: options["force_polling"]
67
67
  ) do |modified, added, removed|
68
68
  c = modified + added + removed
69
+
70
+ # NOTE: inexplicably, this matcher doesn't work with the Listen gem, so
71
+ # we have to run it here manually
72
+ c.reject! { component_frontend_matcher(options).match? _1 }
69
73
  n = c.length
74
+ next if n.zero?
70
75
 
71
76
  unless site.ssr?
72
77
  Bridgetown.logger.info(
73
78
  "Reloading…",
74
- "#{n} file#{"s" if c.length > 1} changed at #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
79
+ "#{n} file#{"s" if n > 1} changed at #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
75
80
  )
76
81
  c.each { |path| Bridgetown.logger.info "", "- #{path["#{site.root_dir}/".length..]}" }
77
82
  end
@@ -93,7 +98,6 @@ module Bridgetown
93
98
  catch :halt do
94
99
  Bridgetown::Hooks.trigger :site, :pre_reload, site, paths
95
100
  Bridgetown::Hooks.clear_reloadable_hooks
96
- site.plugin_manager.reload_plugin_files
97
101
  site.loaders_manager.reload_loaders
98
102
  Bridgetown::Hooks.trigger :site, :post_reload, site, paths
99
103
 
@@ -124,12 +128,15 @@ module Bridgetown
124
128
  end
125
129
 
126
130
  def custom_excludes(options)
127
- Array(options["exclude"]).map { |e| Bridgetown.sanitized_path(options["source"], e) }
131
+ Array(options["exclude"]).map { |e| Bridgetown.sanitized_path(options["root_dir"], e) }
128
132
  end
129
133
 
130
- def component_frontend_matcher
131
- %r{_components/.*?(\.js|\.jsx|\.js\.rb|\.css)$}
134
+ # rubocop:disable Layout/LineLength
135
+ def component_frontend_matcher(options)
136
+ @fematcher ||=
137
+ %r{(#{options[:components_dir]}|#{options[:islands_dir]})/(?:[^.]+|\.(?!dsd))+(\.js|\.jsx|\.js\.rb|\.css)$}
132
138
  end
139
+ # rubocop:enable Layout/LineLength
133
140
 
134
141
  def to_exclude(options)
135
142
  [
@@ -162,7 +169,7 @@ module Bridgetown
162
169
  rescue ArgumentError
163
170
  # Could not find a relative path
164
171
  end
165
- end + [component_frontend_matcher] + [%r!^\.bridgetown-metadata!]
172
+ end
166
173
  end
167
174
 
168
175
  def sleep_forever
@@ -1,13 +1,22 @@
1
+ <%- if frontend_bundling_option == "esbuild" -%>
2
+ <%- if postcss_option -%>
3
+ import "$styles/index.css"
4
+ <%- else -%>
5
+ import "$styles/index.scss"
6
+ <%- end -%>
7
+ import "$styles/syntax-highlighting.css"
8
+ <%- else -%>
1
9
  <%- if postcss_option -%>
2
10
  import "index.css"
3
11
  <%- else -%>
4
12
  import "index.scss"
5
13
  <%- end -%>
6
14
  import "syntax-highlighting.css"
15
+ <%- end -%>
7
16
 
8
17
  // Import all JavaScript & CSS files from src/_components
9
18
  <%- if frontend_bundling_option == "esbuild" -%>
10
- import components from "bridgetownComponents/**/*.{js,jsx,js.rb,css}"
19
+ import components from "$components/**/*.{js,jsx,js.rb,css}"
11
20
  <%- else -%>
12
21
  const componentsContext = require.context("bridgetownComponents", true, /\.(js|css)$/)
13
22
  componentsContext.keys().forEach(componentsContext)
@@ -15,29 +15,29 @@
15
15
  <%- if frontend_bundling_option == "webpack" -%>
16
16
  "css-loader": "^6.7.1",
17
17
  <%- end -%>
18
- "esbuild": "^0.15.12",
18
+ "esbuild": "^0.17.19",
19
19
  <%- if frontend_bundling_option == "webpack" -%>
20
20
  "esbuild-loader": "^2.18.0",
21
21
  "mini-css-extract-plugin": "^2.6.0",
22
22
  <%- else -%>
23
- "glob": "^8.0.1",
23
+ "glob": "^10.2.6",
24
24
  <%- end -%>
25
25
  <%- unless disable_postcss? -%>
26
- "postcss": "^8.4.12",
26
+ "postcss": "^8.4.23",
27
27
  "postcss-flexbugs-fixes": "^5.0.2",
28
28
  <%- if frontend_bundling_option == "esbuild" -%>
29
- "postcss-import": "^14.1.0",
29
+ "postcss-import": "^15.1.0",
30
30
  "postcss-load-config": "^4.0.1",
31
31
  <%- else -%>
32
32
  "postcss-loader": "^6.2.1",
33
33
  <%- end -%>
34
- "postcss-preset-env": "^7.4.3",
34
+ "postcss-preset-env": "^8.4.1",
35
35
  <%- if frontend_bundling_option == "esbuild" -%>
36
36
  "read-cache": "^1.0.0"<%= "," unless postcss_option %>
37
37
  <%- end -%>
38
38
  <%- end -%>
39
39
  <%- unless postcss_option -%>
40
- "sass": "^1.50.1",
40
+ "sass": "^1.62.1",
41
41
  "sass-loader": "^12.6.0"<%= "," if frontend_bundling_option == "webpack" %>
42
42
  <%- end -%>
43
43
  <%- if frontend_bundling_option == "webpack" -%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.beta1
4
+ version: 1.3.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-01 00:00:00.000000000 Z
11
+ date: 2023-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -348,6 +348,7 @@ files:
348
348
  - lib/bridgetown-core/commands/esbuild.rb
349
349
  - lib/bridgetown-core/commands/esbuild/esbuild.config.js
350
350
  - lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb
351
+ - lib/bridgetown-core/commands/esbuild/jsconfig.json
351
352
  - lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb
352
353
  - lib/bridgetown-core/commands/esbuild/setup.rb
353
354
  - lib/bridgetown-core/commands/esbuild/update.rb
@@ -392,6 +393,7 @@ files:
392
393
  - lib/bridgetown-core/configurations/cypress/cypress_tasks
393
394
  - lib/bridgetown-core/configurations/gh-pages.rb
394
395
  - lib/bridgetown-core/configurations/gh-pages/gh-pages.yml
396
+ - lib/bridgetown-core/configurations/is-land.rb
395
397
  - lib/bridgetown-core/configurations/lit.rb
396
398
  - lib/bridgetown-core/configurations/lit/esbuild-plugins.js
397
399
  - lib/bridgetown-core/configurations/lit/happy-days.lit.js
@@ -408,6 +410,7 @@ files:
408
410
  - lib/bridgetown-core/configurations/render/render.yaml.erb
409
411
  - lib/bridgetown-core/configurations/ruby2js.rb
410
412
  - lib/bridgetown-core/configurations/ruby2js/hello_world.js.rb
413
+ - lib/bridgetown-core/configurations/ruby2js/ruby2js.rb
411
414
  - lib/bridgetown-core/configurations/shoelace.rb
412
415
  - lib/bridgetown-core/configurations/stimulus.rb
413
416
  - lib/bridgetown-core/configurations/tailwindcss.rb
@@ -444,6 +447,7 @@ files:
444
447
  - lib/bridgetown-core/filters/date_filters.rb
445
448
  - lib/bridgetown-core/filters/from_liquid.rb
446
449
  - lib/bridgetown-core/filters/grouping_filters.rb
450
+ - lib/bridgetown-core/filters/localization_filters.rb
447
451
  - lib/bridgetown-core/filters/translation_filters.rb
448
452
  - lib/bridgetown-core/filters/url_filters.rb
449
453
  - lib/bridgetown-core/frontmatter_defaults.rb
@@ -490,8 +494,10 @@ files:
490
494
  - lib/bridgetown-core/static_file.rb
491
495
  - lib/bridgetown-core/tags/asset_path.rb
492
496
  - lib/bridgetown-core/tags/class_map.rb
497
+ - lib/bridgetown-core/tags/dsd.rb
493
498
  - lib/bridgetown-core/tags/find.rb
494
499
  - lib/bridgetown-core/tags/highlight.rb
500
+ - lib/bridgetown-core/tags/l.rb
495
501
  - lib/bridgetown-core/tags/link.rb
496
502
  - lib/bridgetown-core/tags/live_reload_dev_js.rb
497
503
  - lib/bridgetown-core/tags/post_url.rb